This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
#Setup working directory
setwd("C:/Users/nj35/OneDrive - University of St Andrews/Masters/MoSeq R-Analysis")
getwd()
#download packages for managing r packages and excel
install.packages("pacman")
install.packages("readxl")
install.packages("tidyverse")
install.packages("emmeans")
install.packages("afex")
install.packages("installr")
install.packages("conflicted")
install.packages("sandwich")
install.packages("lmtest")
install.packages("geepack")
install.packages("tibble")
install.packages("effectsize")
install.packages("lmerTest")
install.packages("robustlmm")
install.packages("clubSandwich")
#load packages
library(pacman)
library(readxl)
library(tidyverse) #includes ggplot and dplyr
library(tibble)
library(emmeans)
library(conflicted)
library(afex)
library(lme4) #LMM model
library(lmerTest) # For p-values in LMM
library(Matrix)
library(car)
library(tibble)
library(effectsize)
library(geepack)
library(robustlmm)
library(clubSandwich)
installr::updateR()
#load results file and make sure headings and levels are established
df_oft <- read.csv("new_moseq_OFT_stats.csv", header=TRUE)
df_oft$syllable <- factor(df_oft$syllable) # Convert to categorical
df_oft$group <- factor(df_oft$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
#cool fact, code above sets "control" as baseline value as it comes first
df_oft$ID <- factor(df_oft$ID)
conflicted::conflicts_prefer(lmer::afex)
[conflicted] Removing existing preference.[conflicted] Will prefer lmer::afex over any other package.
#compare models
#model_complex <- lmer(frequency ~ syllable * group + (syllable | group), data = df_oft) #With (syllable | group) the model learns different patterns for each group, also not repeated measure don't use.
model_simple <- lm(frequency ~ group * syllable, data = df_oft) #not LMM, not repeated measures DO NOT USE.
model_name <- lmer(frequency ~ group * syllable + (1 | ID), data = df_oft) #not used as variation is too small between #individual mice, i.e dropouts reduce sample size so it does not contribute significance towards the model.
boundary (singular) fit: see help('isSingular')
#model_random <- lmer(frequency ~ syllable * group + (1 | group), data = df_oft) #random effects by group
#model_syllable_name <- lmer(frequency ~ syllable * group + (syllable | name), data = df_oft)
#model_1_syllable <- lmer(frequency ~ group * syllable + (1 | syllable), data = df_oft)
#(1 | name) model might be correct?
# Get the AIC values for each model, lower AIC = better
#AIC(model_1_syllable, model_name)
anova(model_name,model_simple) #thus, use model_name
refitting model(s) with ML (instead of REML)
Data: df_oft
Models:
model_simple: frequency ~ group * syllable
model_name: frequency ~ group * syllable + (1 | ID)
npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
model_simple 88 -4790 -4360 2483 -4966
model_name 89 -4788 -4353 2483 -4966 0 1 1
model_simple <- lm(frequency ~ group * syllable, data = df_oft) #removed repeated measures random variance, still works
summary(model_simple)
Call:
lm(formula = frequency ~ group * syllable, data = df_oft)
Residuals:
Min 1Q Median 3Q Max
-0.106389 -0.009781 -0.002118 0.008713 0.119748
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.1694566 0.0062772 26.996 < 2e-16 ***
grouppost_w1 -0.0007978 0.0088773 -0.090 0.928414
grouppost_w2 -0.0159092 0.0092721 -1.716 0.086620 .
syllable1 -0.0541551 0.0088773 -6.100 1.72e-09 ***
syllable2 -0.0504198 0.0088773 -5.680 1.95e-08 ***
syllable3 -0.0860340 0.0088773 -9.691 < 2e-16 ***
syllable4 -0.1032257 0.0088773 -11.628 < 2e-16 ***
syllable5 -0.1238616 0.0088773 -13.953 < 2e-16 ***
syllable6 -0.1153807 0.0088773 -12.997 < 2e-16 ***
syllable7 -0.1504951 0.0088773 -16.953 < 2e-16 ***
syllable8 -0.1514627 0.0088773 -17.062 < 2e-16 ***
syllable9 -0.1297608 0.0088773 -14.617 < 2e-16 ***
syllable10 -0.1183141 0.0088773 -13.328 < 2e-16 ***
syllable11 -0.1269136 0.0088773 -14.296 < 2e-16 ***
syllable12 -0.1420409 0.0088773 -16.000 < 2e-16 ***
syllable13 -0.1446978 0.0090604 -15.970 < 2e-16 ***
syllable14 -0.1589926 0.0095199 -16.701 < 2e-16 ***
syllable15 -0.1636904 0.0092721 -17.654 < 2e-16 ***
syllable16 -0.1440814 0.0088773 -16.230 < 2e-16 ***
syllable17 -0.1591150 0.0088773 -17.924 < 2e-16 ***
syllable18 -0.1644718 0.0098142 -16.758 < 2e-16 ***
syllable19 -0.1598149 0.0092721 -17.236 < 2e-16 ***
syllable20 -0.1634212 0.0092721 -17.625 < 2e-16 ***
syllable21 -0.1566993 0.0092721 -16.900 < 2e-16 ***
syllable27 -0.1579608 0.0095199 -16.593 < 2e-16 ***
grouppost_w1:syllable1 0.0204656 0.0125544 1.630 0.103501
grouppost_w2:syllable1 0.0092755 0.0131127 0.707 0.479565
grouppost_w1:syllable2 0.0312975 0.0125544 2.493 0.012890 *
grouppost_w2:syllable2 0.0216526 0.0131127 1.651 0.099113 .
grouppost_w1:syllable3 -0.0134163 0.0125544 -1.069 0.285580
grouppost_w2:syllable3 -0.0287779 0.0131127 -2.195 0.028503 *
grouppost_w1:syllable4 -0.0051913 0.0125544 -0.414 0.679362
grouppost_w2:syllable4 0.0293362 0.0131127 2.237 0.025572 *
grouppost_w1:syllable5 0.0014351 0.0125544 0.114 0.909021
grouppost_w2:syllable5 0.0264099 0.0131127 2.014 0.044368 *
grouppost_w1:syllable6 -0.0105937 0.0125544 -0.844 0.399046
grouppost_w2:syllable6 0.0106076 0.0131127 0.809 0.418801
grouppost_w1:syllable7 0.0069355 0.0125544 0.552 0.580817
grouppost_w2:syllable7 0.0375339 0.0131127 2.862 0.004325 **
grouppost_w1:syllable8 0.0174386 0.0126845 1.375 0.169619
grouppost_w2:syllable8 0.0314753 0.0132890 2.369 0.018120 *
grouppost_w1:syllable9 -0.0119392 0.0125544 -0.951 0.341922
grouppost_w2:syllable9 0.0073871 0.0132890 0.556 0.578462
grouppost_w1:syllable10 -0.0156595 0.0125544 -1.247 0.212678
grouppost_w2:syllable10 0.0005750 0.0131127 0.044 0.965035
grouppost_w1:syllable11 -0.0217642 0.0125544 -1.734 0.083414 .
grouppost_w2:syllable11 -0.0181633 0.0137624 -1.320 0.187325
grouppost_w1:syllable12 -0.0074175 0.0125544 -0.591 0.554821
grouppost_w2:syllable12 0.0178357 0.0131127 1.360 0.174190
grouppost_w1:syllable13 -0.0007122 0.0128133 -0.056 0.955688
grouppost_w2:syllable13 0.0120933 0.0134120 0.902 0.367525
grouppost_w1:syllable14 0.0028061 0.0131422 0.214 0.830984
grouppost_w2:syllable14 0.0237824 0.0135559 1.754 0.079784 .
grouppost_w1:syllable15 0.0059675 0.0128366 0.465 0.642153
grouppost_w2:syllable15 0.0499401 0.0133831 3.732 0.000205 ***
grouppost_w1:syllable16 -0.0120196 0.0126845 -0.948 0.343656
grouppost_w2:syllable16 0.0003552 0.0131127 0.027 0.978394
grouppost_w1:syllable17 0.0069276 0.0126845 0.546 0.585133
grouppost_w2:syllable17 0.0356397 0.0131127 2.718 0.006725 **
grouppost_w1:syllable18 0.0051095 0.0136729 0.374 0.708739
grouppost_w2:syllable18 0.0341112 0.0137643 2.478 0.013428 *
grouppost_w1:syllable19 0.0031452 0.0132890 0.237 0.812972
grouppost_w2:syllable19 0.0194409 0.0137643 1.412 0.158253
grouppost_w1:syllable20 0.0050733 0.0132890 0.382 0.702744
grouppost_w2:syllable20 0.0225881 0.0135559 1.666 0.096085 .
grouppost_w1:syllable21 0.0027602 0.0132890 0.208 0.835517
grouppost_w2:syllable21 0.0126556 0.0143428 0.882 0.377870
grouppost_w1:syllable27 0.0057487 0.0131422 0.437 0.661933
grouppost_w2:syllable27 0.0092440 0.0141854 0.652 0.514830
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.02263 on 729 degrees of freedom
Multiple R-squared: 0.796, Adjusted R-squared: 0.777
F-statistic: 41.84 on 68 and 729 DF, p-value: < 2.2e-16
model_var <- lmer(frequency ~ group * syllable,
random = ~1 | ID,
weights = varIdent(form = ~1 | syllable),
data = df_oft)
Error in lmer(frequency ~ group * syllable, random = ~1 | ID, weights = varIdent(form = ~1 | :
unused argument (random = ~1 | ID)
model_oft <- lmer(frequency ~ group * syllable + (1 | ID), data = df_oft)
boundary (singular) fit: see help('isSingular')
summary(model_oft)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_oft
REML criterion at convergence: -4232
Scaled residuals:
Min 1Q Median 3Q Max
-4.655 -0.441 -0.096 0.347 5.477
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.000000 0.00
Residual 0.000399 0.02
Number of obs: 977, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 0.15601 0.00554 890.00000 28.17 < 2e-16 ***
grouppost_w1 0.02151 0.00783 890.00000 2.75 0.00614 **
grouppost_w2 -0.01872 0.00818 890.00000 -2.29 0.02232 *
syllable1 -0.01760 0.00783 890.00000 -2.25 0.02486 *
syllable2 -0.05535 0.00783 890.00000 -7.07 3.2e-12 ***
syllable3 -0.09083 0.00783 890.00000 -11.60 < 2e-16 ***
syllable4 -0.10562 0.00783 890.00000 -13.49 < 2e-16 ***
syllable5 -0.10864 0.00783 890.00000 -13.87 < 2e-16 ***
syllable6 -0.13416 0.00783 890.00000 -17.13 < 2e-16 ***
syllable7 -0.11440 0.00783 890.00000 -14.61 < 2e-16 ***
syllable8 -0.12602 0.00783 890.00000 -16.09 < 2e-16 ***
syllable9 -0.10969 0.00783 890.00000 -14.01 < 2e-16 ***
syllable10 -0.14808 0.00799 890.00000 -18.53 < 2e-16 ***
syllable11 -0.11148 0.00783 890.00000 -14.23 < 2e-16 ***
syllable12 -0.14082 0.00799 890.00000 -17.62 < 2e-16 ***
syllable13 -0.13796 0.00783 890.00000 -17.61 < 2e-16 ***
syllable14 -0.13986 0.00783 890.00000 -17.86 < 2e-16 ***
syllable15 -0.14695 0.00818 890.00000 -17.96 < 2e-16 ***
syllable16 -0.14019 0.00783 890.00000 -17.90 < 2e-16 ***
syllable17 -0.14585 0.00799 890.00000 -18.25 < 2e-16 ***
syllable18 -0.14082 0.00840 890.00000 -16.77 < 2e-16 ***
syllable19 -0.15080 0.00866 890.00000 -17.42 < 2e-16 ***
syllable20 -0.13212 0.00799 890.00000 -16.53 < 2e-16 ***
syllable21 -0.13229 0.00783 890.00000 -16.89 < 2e-16 ***
syllable22 -0.14132 0.00799 890.00000 -17.68 < 2e-16 ***
syllable23 -0.14310 0.00818 890.00000 -17.49 < 2e-16 ***
syllable24 -0.14771 0.00799 890.00000 -18.48 < 2e-16 ***
syllable25 -0.14795 0.00799 890.00000 -18.51 < 2e-16 ***
syllable26 -0.14799 0.00818 890.00000 -18.09 < 2e-16 ***
syllable27 -0.15026 0.00936 890.00000 -16.05 < 2e-16 ***
syllable28 -0.14648 0.00840 890.00000 -17.44 < 2e-16 ***
grouppost_w1:syllable1 -0.01095 0.01108 890.00000 -0.99 0.32319
grouppost_w2:syllable1 0.02279 0.01157 890.00000 1.97 0.04916 *
grouppost_w1:syllable2 -0.03385 0.01108 890.00000 -3.06 0.00231 **
grouppost_w2:syllable2 -0.03127 0.01157 890.00000 -2.70 0.00700 **
grouppost_w1:syllable3 -0.01601 0.01108 890.00000 -1.45 0.14879
grouppost_w2:syllable3 0.05035 0.01157 890.00000 4.35 1.5e-05 ***
grouppost_w1:syllable4 -0.00879 0.01108 890.00000 -0.79 0.42775
grouppost_w2:syllable4 0.06689 0.01157 890.00000 5.78 1.0e-08 ***
grouppost_w1:syllable5 -0.03146 0.01108 890.00000 -2.84 0.00461 **
grouppost_w2:syllable5 0.01689 0.01157 890.00000 1.46 0.14476
grouppost_w1:syllable6 -0.01673 0.01108 890.00000 -1.51 0.13130
grouppost_w2:syllable6 0.04199 0.01157 890.00000 3.63 0.00030 ***
grouppost_w1:syllable7 -0.03748 0.01108 890.00000 -3.38 0.00075 ***
grouppost_w2:syllable7 0.00526 0.01157 890.00000 0.45 0.64973
grouppost_w1:syllable8 -0.01837 0.01108 890.00000 -1.66 0.09754 .
grouppost_w2:syllable8 0.01160 0.01157 890.00000 1.00 0.31648
grouppost_w1:syllable9 -0.04496 0.01108 890.00000 -4.06 5.4e-05 ***
grouppost_w2:syllable9 -0.01053 0.01157 890.00000 -0.91 0.36276
grouppost_w1:syllable10 -0.01142 0.01119 890.00000 -1.02 0.30778
grouppost_w2:syllable10 0.06632 0.01168 890.00000 5.68 1.8e-08 ***
grouppost_w1:syllable11 -0.04738 0.01133 890.00000 -4.18 3.1e-05 ***
grouppost_w2:syllable11 -0.01525 0.01172 890.00000 -1.30 0.19368
grouppost_w1:syllable12 -0.01107 0.01130 890.00000 -0.98 0.32771
grouppost_w2:syllable12 0.02634 0.01168 890.00000 2.26 0.02433 *
grouppost_w1:syllable13 -0.02410 0.01108 890.00000 -2.18 0.02984 *
grouppost_w2:syllable13 0.02867 0.01157 890.00000 2.48 0.01339 *
grouppost_w1:syllable14 -0.01576 0.01108 890.00000 -1.42 0.15521
grouppost_w2:syllable14 0.02605 0.01157 890.00000 2.25 0.02458 *
grouppost_w1:syllable15 -0.01682 0.01144 890.00000 -1.47 0.14168
grouppost_w2:syllable15 0.03755 0.01181 890.00000 3.18 0.00152 **
grouppost_w1:syllable16 -0.01958 0.01108 890.00000 -1.77 0.07742 .
grouppost_w2:syllable16 0.01452 0.01157 890.00000 1.26 0.20978
grouppost_w1:syllable17 -0.01007 0.01159 890.00000 -0.87 0.38519
grouppost_w2:syllable17 0.02553 0.01202 890.00000 2.12 0.03395 *
grouppost_w1:syllable18 -0.02146 0.01172 890.00000 -1.83 0.06750 .
grouppost_w2:syllable18 0.01961 0.01229 890.00000 1.60 0.11103
grouppost_w1:syllable19 -0.01162 0.01191 890.00000 -0.98 0.32968
grouppost_w2:syllable19 0.04048 0.01229 890.00000 3.29 0.00103 **
grouppost_w1:syllable20 -0.03668 0.01130 890.00000 -3.24 0.00122 **
grouppost_w2:syllable20 0.00171 0.01225 890.00000 0.14 0.88927
grouppost_w1:syllable21 -0.03774 0.01119 890.00000 -3.37 0.00078 ***
grouppost_w2:syllable21 0.00214 0.01405 890.00000 0.15 0.87901
grouppost_w1:syllable22 -0.02178 0.01119 890.00000 -1.95 0.05190 .
grouppost_w2:syllable22 0.00984 0.01202 890.00000 0.82 0.41308
grouppost_w1:syllable23 -0.01973 0.01157 890.00000 -1.71 0.08852 .
grouppost_w2:syllable23 0.01328 0.01237 890.00000 1.07 0.28331
grouppost_w1:syllable24 -0.01789 0.01159 890.00000 -1.54 0.12327
grouppost_w2:syllable24 0.01697 0.01291 890.00000 1.32 0.18884
grouppost_w1:syllable25 -0.02144 0.01144 890.00000 -1.87 0.06122 .
grouppost_w2:syllable25 0.01666 0.01183 890.00000 1.41 0.15939
grouppost_w1:syllable26 -0.02032 0.01144 890.00000 -1.78 0.07590 .
grouppost_w2:syllable26 0.01483 0.01237 890.00000 1.20 0.23088
grouppost_w1:syllable27 -0.01409 0.01297 890.00000 -1.09 0.27752
grouppost_w2:syllable27 0.02020 0.01345 890.00000 1.50 0.13350
grouppost_w1:syllable28 -0.02423 0.01188 890.00000 -2.04 0.04162 *
grouppost_w2:syllable28 0.01317 0.01280 890.00000 1.03 0.30372
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 87 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#assumption check 1 - Normality of residuals (should be normally distributed) - violates
qqnorm(resid(model_oft))
qqline(resid(model_oft))
# non-normal, thus, when calculating confidence intervals, used "boot" method which assumes non-normality
resid_oft <- resid(model_oft)
#provides quantitative values if violates normality. less than 0.05 is non-normal
shap_oft <- shapiro.test(resid_oft)
shap_oft
Shapiro-Wilk normality test
data: resid_oft
W = 0.9, p-value <2e-16
#Assumption 2 - Homoscedasticity (variance should be consistent) - VIOLATES
plot(fitted(model_oft), resid(model_oft))
#violates it, not evenly distributed, thus, Heteroscedasticity
#Assumption 3 - confidence intervals - passes
confint(model_oft, method = "boot")
Computing bootstrap confidence intervals ...
281 message(s): boundary (singular) fit: see help('isSingular')
2.5 % 97.5 %
.sig01 0.00000 0.002230
.sigma 0.01895 0.020948
(Intercept) 0.14612 0.167034
grouppost_w1 0.00713 0.036720
grouppost_w2 -0.03296 -0.003912
syllable1 -0.03225 -0.002897
syllable2 -0.07005 -0.042060
syllable3 -0.10638 -0.074589
syllable4 -0.12110 -0.091126
syllable5 -0.12299 -0.094561
syllable6 -0.14989 -0.118716
syllable7 -0.13033 -0.099076
syllable8 -0.14101 -0.110910
syllable9 -0.12493 -0.094528
syllable10 -0.16516 -0.134015
syllable11 -0.12568 -0.097310
syllable12 -0.15676 -0.126014
syllable13 -0.15215 -0.122383
syllable14 -0.15370 -0.124666
syllable15 -0.16344 -0.132045
syllable16 -0.15546 -0.126089
syllable17 -0.16128 -0.130129
syllable18 -0.15637 -0.125103
syllable19 -0.16779 -0.135503
syllable20 -0.14874 -0.117694
syllable21 -0.14925 -0.118738
syllable22 -0.15706 -0.126756
syllable23 -0.16029 -0.127930
syllable24 -0.16256 -0.132881
syllable25 -0.16519 -0.132813
syllable26 -0.16251 -0.132502
syllable27 -0.16745 -0.132824
syllable28 -0.16296 -0.130890
grouppost_w1:syllable1 -0.03135 0.010747
grouppost_w2:syllable1 0.00300 0.045373
grouppost_w1:syllable2 -0.05531 -0.013519
grouppost_w2:syllable2 -0.05303 -0.010534
grouppost_w1:syllable3 -0.03760 0.006407
grouppost_w2:syllable3 0.02880 0.071562
grouppost_w1:syllable4 -0.02935 0.010954
grouppost_w2:syllable4 0.04467 0.089574
grouppost_w1:syllable5 -0.05187 -0.009801
grouppost_w2:syllable5 -0.00323 0.037125
grouppost_w1:syllable6 -0.04115 0.005300
grouppost_w2:syllable6 0.01964 0.064769
grouppost_w1:syllable7 -0.05798 -0.015803
grouppost_w2:syllable7 -0.01646 0.027415
grouppost_w1:syllable8 -0.03914 0.004308
grouppost_w2:syllable8 -0.01170 0.032100
grouppost_w1:syllable9 -0.06613 -0.024760
grouppost_w2:syllable9 -0.03091 0.009827
grouppost_w1:syllable10 -0.03294 0.009782
grouppost_w2:syllable10 0.04656 0.090465
grouppost_w1:syllable11 -0.06891 -0.026890
grouppost_w2:syllable11 -0.03785 0.005965
grouppost_w1:syllable12 -0.03221 0.011758
grouppost_w2:syllable12 0.00641 0.051236
grouppost_w1:syllable13 -0.04635 -0.001630
grouppost_w2:syllable13 0.00637 0.052602
grouppost_w1:syllable14 -0.03649 0.005699
grouppost_w2:syllable14 0.00551 0.048488
grouppost_w1:syllable15 -0.03718 0.005688
grouppost_w2:syllable15 0.01513 0.060396
grouppost_w1:syllable16 -0.04050 0.002193
grouppost_w2:syllable16 -0.00790 0.037258
grouppost_w1:syllable17 -0.03240 0.010733
grouppost_w2:syllable17 0.00352 0.046617
grouppost_w1:syllable18 -0.04729 0.000497
grouppost_w2:syllable18 -0.00209 0.043025
grouppost_w1:syllable19 -0.03360 0.012657
grouppost_w2:syllable19 0.01829 0.064728
grouppost_w1:syllable20 -0.05902 -0.012136
grouppost_w2:syllable20 -0.02206 0.029463
grouppost_w1:syllable21 -0.05841 -0.016421
grouppost_w2:syllable21 -0.02520 0.027752
grouppost_w1:syllable22 -0.04522 -0.001320
grouppost_w2:syllable22 -0.01334 0.030377
grouppost_w1:syllable23 -0.04345 0.001745
grouppost_w2:syllable23 -0.01080 0.034210
grouppost_w1:syllable24 -0.03982 0.005770
grouppost_w2:syllable24 -0.00783 0.039704
grouppost_w1:syllable25 -0.04414 -0.000317
grouppost_w2:syllable25 -0.00632 0.040438
grouppost_w1:syllable26 -0.04384 0.000653
grouppost_w2:syllable26 -0.00898 0.038409
grouppost_w1:syllable27 -0.03816 0.010404
grouppost_w2:syllable27 -0.00364 0.044968
grouppost_w1:syllable28 -0.04780 0.001631
grouppost_w2:syllable28 -0.01122 0.039968
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
# Obtain estimated marginal means
emm_oft <- emmeans(model_oft, ~ group | syllable) # Pairwise comparisons of syllable effects within each group
head(emm_oft)
group syllable emmean SE df lower.CL upper.CL
control 0 0.156 0.00554 890 0.145 0.167
post_w1 0 0.177 0.00554 890 0.167 0.188
post_w2 0 0.137 0.00602 890 0.126 0.149
control 1 0.138 0.00554 890 0.128 0.149
post_w1 1 0.149 0.00554 890 0.138 0.160
post_w2 1 0.142 0.00602 890 0.131 0.154
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_oft <- contrast(emm_oft, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm
summary(pairwise_oft)
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0215 0.00783 878 -2.750 0.0170
control - post_w2 0.0187 0.00818 880 2.290 0.0580
post_w1 - post_w2 0.0402 0.00818 880 4.920 <.0001
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0106 0.00783 878 -1.350 0.3690
control - post_w2 -0.0041 0.00818 880 -0.500 0.8730
post_w1 - post_w2 0.0065 0.00818 880 0.790 0.7070
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0123 0.00783 878 1.580 0.2570
control - post_w2 0.0500 0.00818 880 6.110 <.0001
post_w1 - post_w2 0.0377 0.00818 880 4.600 <.0001
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0055 0.00783 878 -0.700 0.7620
control - post_w2 -0.0316 0.00818 880 -3.870 <.0001
post_w1 - post_w2 -0.0261 0.00818 880 -3.190 0.0040
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0127 0.00783 878 -1.620 0.2360
control - post_w2 -0.0482 0.00818 880 -5.890 <.0001
post_w1 - post_w2 -0.0354 0.00818 880 -4.330 <.0001
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0099 0.00783 878 1.270 0.4120
control - post_w2 0.0018 0.00818 880 0.220 0.9730
post_w1 - post_w2 -0.0081 0.00818 880 -0.990 0.5830
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0048 0.00783 878 -0.610 0.8140
control - post_w2 -0.0233 0.00818 880 -2.840 0.0130
post_w1 - post_w2 -0.0185 0.00818 880 -2.260 0.0620
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0160 0.00783 878 2.040 0.1040
control - post_w2 0.0135 0.00818 880 1.650 0.2270
post_w1 - post_w2 -0.0025 0.00818 880 -0.310 0.9500
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0031 0.00783 878 -0.400 0.9150
control - post_w2 0.0071 0.00818 880 0.870 0.6590
post_w1 - post_w2 0.0103 0.00818 880 1.260 0.4210
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0234 0.00783 878 2.990 0.0080
control - post_w2 0.0293 0.00818 880 3.580 0.0010
post_w1 - post_w2 0.0058 0.00818 880 0.710 0.7580
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0101 0.00799 879 -1.260 0.4170
control - post_w2 -0.0476 0.00834 879 -5.710 <.0001
post_w1 - post_w2 -0.0375 0.00818 880 -4.580 <.0001
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0259 0.00818 880 3.160 0.0050
control - post_w2 0.0340 0.00840 881 4.040 <.0001
post_w1 - post_w2 0.0081 0.00873 881 0.930 0.6230
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0104 0.00815 880 -1.280 0.4060
control - post_w2 -0.0076 0.00834 881 -0.910 0.6320
post_w1 - post_w2 0.0028 0.00834 881 0.340 0.9390
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0026 0.00783 878 0.330 0.9420
control - post_w2 -0.0099 0.00818 880 -1.220 0.4440
post_w1 - post_w2 -0.0125 0.00818 880 -1.530 0.2760
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0058 0.00783 878 -0.730 0.7430
control - post_w2 -0.0073 0.00818 880 -0.900 0.6430
post_w1 - post_w2 -0.0016 0.00818 880 -0.190 0.9800
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0047 0.00834 879 -0.560 0.8400
control - post_w2 -0.0188 0.00852 882 -2.210 0.0700
post_w1 - post_w2 -0.0141 0.00834 881 -1.700 0.2080
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0019 0.00783 878 -0.250 0.9670
control - post_w2 0.0042 0.00818 880 0.510 0.8650
post_w1 - post_w2 0.0061 0.00818 880 0.750 0.7340
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0114 0.00855 880 -1.340 0.3750
control - post_w2 -0.0068 0.00881 883 -0.770 0.7200
post_w1 - post_w2 0.0046 0.00918 882 0.510 0.8690
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0001 0.00873 881 -0.010 1.0000
control - post_w2 -0.0009 0.00918 882 -0.100 0.9950
post_w1 - post_w2 -0.0008 0.00898 880 -0.090 0.9950
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0099 0.00898 884 -1.100 0.5130
control - post_w2 -0.0218 0.00918 884 -2.370 0.0470
post_w1 - post_w2 -0.0119 0.00873 881 -1.360 0.3630
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0152 0.00815 880 1.860 0.1510
control - post_w2 0.0170 0.00912 884 1.870 0.1490
post_w1 - post_w2 0.0019 0.00912 882 0.200 0.9780
syllable = 21:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0162 0.00799 879 2.030 0.1060
control - post_w2 0.0166 0.01140 887 1.450 0.3150
post_w1 - post_w2 0.0004 0.01150 887 0.030 0.9990
syllable = 22:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0003 0.00799 879 0.030 0.9990
control - post_w2 0.0089 0.00881 883 1.010 0.5720
post_w1 - post_w2 0.0086 0.00866 882 0.990 0.5810
syllable = 23:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0018 0.00852 880 -0.210 0.9760
control - post_w2 0.0054 0.00928 884 0.590 0.8270
post_w1 - post_w2 0.0072 0.00928 882 0.780 0.7160
syllable = 24:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0036 0.00855 882 -0.420 0.9060
control - post_w2 0.0017 0.00999 885 0.180 0.9830
post_w1 - post_w2 0.0054 0.01030 883 0.520 0.8610
syllable = 25:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0001 0.00834 881 -0.010 1.0000
control - post_w2 0.0021 0.00855 882 0.240 0.9690
post_w1 - post_w2 0.0021 0.00873 883 0.240 0.9680
syllable = 26:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0012 0.00834 881 -0.140 0.9890
control - post_w2 0.0039 0.00928 882 0.420 0.9080
post_w1 - post_w2 0.0051 0.00912 884 0.560 0.8430
syllable = 27:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0074 0.01030 882 -0.720 0.7530
control - post_w2 -0.0015 0.01070 886 -0.140 0.9900
post_w1 - post_w2 0.0060 0.01030 885 0.580 0.8330
syllable = 28:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0027 0.00893 882 0.300 0.9500
control - post_w2 0.0056 0.00985 887 0.560 0.8390
post_w1 - post_w2 0.0028 0.00985 886 0.290 0.9550
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
#this data will be used for plotting
# Convert the pairwise results into a data frame using summary
pairwise_results_oft <- summary(pairwise_oft)
# Filter significant results (p-value < 0.05)
sig_results_oft <- pairwise_results_oft[pairwise_results_oft$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_oft <- sig_results_oft %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
# Print sig_syllables to check
print(sig_syllables_oft)
NA
# Calculate how many significant pairs there are at different thresholds
pairwise_results_oft <- summary(pairwise_oft)
# Count significant p-values at different thresholds
sig_counts <- list(
p_05 = sum(pairwise_results_oft$p.value < 0.05, na.rm = TRUE),
p_01 = sum(pairwise_results_oft$p.value < 0.01, na.rm = TRUE),
p_001 = sum(pairwise_results_oft$p.value < 0.001, na.rm = TRUE),
total_under_05 = sum(pairwise_results_oft$p.value < 0.05, na.rm = TRUE) # Count all p-values < 0.05
)
# Print the counts
cat("Number of significant comparisons:\n")
Number of significant comparisons:
cat("p < 0.05:", sig_counts$p_05, "\n")
p < 0.05: 16
cat("p < 0.01:", sig_counts$p_01, "\n")
p < 0.01: 13
cat("p < 0.001:", sig_counts$p_001, "\n")
p < 0.001: 9
cat("Total number of p-values at any <0.05:", sig_counts$total_under_05, "\n") # Print total number of p-values < 0.05
Total number of p-values at any <0.05: 16
# To get the specific contrasts with significant differences (p < 0.05)
sig_contrasts <- pairwise_results_oft[pairwise_results_oft$p.value < 0.05, ]
print("Significant contrasts with p < 0.05:")
[1] "Significant contrasts with p < 0.05:"
print(sig_contrasts)
contrast syllable estimate SE df t.ratio p.value
control - post_w1 0 -0.0215 0.00783 878 -2.750 0.0169
post_w1 - post_w2 0 0.0402 0.00818 880 4.920 <.0001
control - post_w2 2 0.0500 0.00818 880 6.110 <.0001
post_w1 - post_w2 2 0.0377 0.00818 880 4.600 <.0001
control - post_w2 3 -0.0316 0.00818 880 -3.870 0.0004
post_w1 - post_w2 3 -0.0261 0.00818 880 -3.190 0.0042
control - post_w2 4 -0.0482 0.00818 880 -5.890 <.0001
post_w1 - post_w2 4 -0.0354 0.00818 880 -4.330 <.0001
control - post_w2 6 -0.0233 0.00818 880 -2.840 0.0127
control - post_w1 9 0.0234 0.00783 878 2.990 0.0080
control - post_w2 9 0.0293 0.00818 880 3.580 0.0011
control - post_w2 10 -0.0476 0.00834 879 -5.710 <.0001
post_w1 - post_w2 10 -0.0375 0.00818 880 -4.580 <.0001
control - post_w1 11 0.0259 0.00818 880 3.160 0.0046
control - post_w2 11 0.0340 0.00840 881 4.040 0.0002
control - post_w2 19 -0.0218 0.00918 884 -2.370 0.0472
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
# Optionally, you can filter by different p-value thresholds
sig_by_01 <- pairwise_results_oft[pairwise_results_oft$p.value < 0.01, ]
sig_by_001 <- pairwise_results_oft[pairwise_results_oft$p.value < 0.001, ]
# Print significant results by stricter thresholds
cat("\nSignificant contrasts with p < 0.01:\n")
Significant contrasts with p < 0.01:
print(sig_by_01)
contrast syllable estimate SE df t.ratio p.value
post_w1 - post_w2 0 0.0402 0.00818 880 4.920 <.0001
control - post_w2 2 0.0500 0.00818 880 6.110 <.0001
post_w1 - post_w2 2 0.0377 0.00818 880 4.600 <.0001
control - post_w2 3 -0.0316 0.00818 880 -3.870 0.0004
post_w1 - post_w2 3 -0.0261 0.00818 880 -3.190 0.0042
control - post_w2 4 -0.0482 0.00818 880 -5.890 <.0001
post_w1 - post_w2 4 -0.0354 0.00818 880 -4.330 <.0001
control - post_w1 9 0.0234 0.00783 878 2.990 0.0080
control - post_w2 9 0.0293 0.00818 880 3.580 0.0011
control - post_w2 10 -0.0476 0.00834 879 -5.710 <.0001
post_w1 - post_w2 10 -0.0375 0.00818 880 -4.580 <.0001
control - post_w1 11 0.0259 0.00818 880 3.160 0.0046
control - post_w2 11 0.0340 0.00840 881 4.040 0.0002
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
cat("\nSignificant contrasts with p < 0.001:\n")
Significant contrasts with p < 0.001:
print(sig_by_001)
contrast syllable estimate SE df t.ratio p.value
post_w1 - post_w2 0 0.0402 0.00818 880 4.920 <.0001
control - post_w2 2 0.0500 0.00818 880 6.110 <.0001
post_w1 - post_w2 2 0.0377 0.00818 880 4.600 <.0001
control - post_w2 3 -0.0316 0.00818 880 -3.870 0.0004
control - post_w2 4 -0.0482 0.00818 880 -5.890 <.0001
post_w1 - post_w2 4 -0.0354 0.00818 880 -4.330 <.0001
control - post_w2 10 -0.0476 0.00834 879 -5.710 <.0001
post_w1 - post_w2 10 -0.0375 0.00818 880 -4.580 <.0001
control - post_w2 11 0.0340 0.00840 881 4.040 0.0002
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
# summary Count significant comparisons by groups (filtering by p-value < 0.05)
cat("\nSignificant comparisons by contrast type:\n")
Significant comparisons by contrast type:
if("contrast" %in% colnames(pairwise_results_oft)) {
# Count by contrast type (e.g., specific group comparisons)
sig_by_contrast <- table(pairwise_results_oft$contrast[pairwise_results_oft$p.value < 0.05])
print(sig_by_contrast)
}
control - post_w1 control - post_w2 post_w1 - post_w2
3 8 5
#for ggplot below
syllable_labels_oft <- c(
"0" = "0 (rear_supported)",
"1" = "1 (sniff_stationary)",
"2" = "2 (sniff_locomotion)",
"3" = "3 (stand-still)",
"4" = "4 (turn_left_sharp)",
"5" = "5 (thigmotaxis_right)",
"6" = "6 (turn_right_sharp)",
"7" = "7 (rear_supported_left_traverse)",
"8" = "8 (thigmotaxis_left)",
"9" = "9 (head_retract_right)",
"10" = "10 (turn_left_moderate)",
"11" = "11 (sniff_up)",
"12" = "12 (rear_support_right_multiple)",
"13" = "13 (rear_support_left_multiple)",
"14" = "14 (rear_supported_right_traverse)",
"15" = "15 (turn_left_wide)",
"16" = "16 (turn_right_moderate)",
"17" = "17 (acceleration_right)",
"18" = "18 (acceleration_left)",
"19" = "19 (slide)",
"20" = "20 (turn_right_wide)",
"21" = "21 (groom_sit)",
"22" = "22 (rear_support_lean)",
"23" = "23 (thigmotaxsis_head_tilt)",
"24" = "24 (acceleration_forward)",
"25" = "25 (hunch_sniff)",
"26" = "26 (head_retract_left)",
"27" = "27 (groom_curl)"
)
# Calculate means by syllable and group
oft_means <- df_oft %>%
group_by(syllable, group) %>%
summarize(
mean_freq_oft = mean(frequency, na.rm = TRUE),
se_oft = sd(frequency, na.rm = TRUE)/sqrt(n())
)
`summarise()` has grouped output by 'syllable'. You can override using the `.groups` argument.
# Create the plot
plot_oft <- ggplot(oft_means, aes(x = syllable, y = mean_freq_oft, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = mean_freq_oft - se_oft, ymax = mean_freq_oft + se_oft), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0))
)
# Add significance asterisks
plot_oft <- plot_oft + geom_text(
data = sig_syllables_oft,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_oft
#ggsave("oft_graph.png", plot = plot_oft, width = 10, height = 6) #makes spaces visible
#OFT_relative_control
# Calculate means by syllable and group
oft_means <- df_oft %>%
group_by(syllable, group) %>%
summarize(
mean_freq_oft = mean(frequency, na.rm = TRUE),
se_oft = sd(frequency, na.rm = TRUE)/sqrt(n())
)
`summarise()` has grouped output by 'syllable'. You can override using the `.groups` argument.
# Step 1: Calculate mean for control group
control_means <- oft_means %>%
filter(group == "control") %>%
select(syllable, control_mean_freq_oft = mean_freq_oft)
# Step 2: Join the control mean to the main dataset and calculate the relative frequency
oft_means_relative <- oft_means %>%
left_join(control_means, by = "syllable") %>% # Join control means
mutate(mean_freq_relative = mean_freq_oft - control_mean_freq_oft)
print(oft_means_relative)
# Create the plot with relative values
plot_oft_2 <- ggplot(oft_means_relative, aes(x = syllable, y = mean_freq_relative, color = group, group = group)) +
geom_line(size = 1) +
geom_point(size = 3) +
geom_errorbar(aes(ymin = mean_freq_relative - se_oft, ymax = mean_freq_relative + se_oft), width = 0.2) +
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft) +
labs(
x = "Syllable Order by Frequency",
y = "Frequency (relative to control)",
color = NULL
) +
geom_hline(yintercept = 0, linetype = "dashed", color = "black") + # Add baseline at 0
ylim(-0.1, 0.2) + # Adjust if needed depending on your data
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0))
)
plot_oft_2
#ggsave("oft_graph_2.png", plot = plot_oft_2, width = 10, height = 6) #makes spaces visible
# Get syllables ordered by mean frequency in control group
syllable_order <- df_oft %>% #syllable_order is the function
filter(group == "control") %>%
group_by(syllable) %>%
summarize(mean_freq = mean(frequency, na.rm = TRUE)) %>%
arrange(desc(mean_freq)) %>% #computed mean frequency sorted from most to least
pull(syllable) # Extract just the ordered syllable names, this controls x-axis of plot
df_oft <- df_oft %>%
mutate(syllable = factor(syllable, levels = syllable_order))
oft_means <- df_oft %>% #recalculate mean and standard error
group_by(syllable, group) %>%
summarize(
mean_freq_oft = mean(frequency, na.rm = TRUE),
se_oft = sd(frequency, na.rm = TRUE)/sqrt(n()),
.groups = "drop"
)
plot_oft_3 <- ggplot(oft_means, aes(x = syllable, y = mean_freq_oft, color = group, group = group)) +
geom_line(size = 1) +
geom_point(size = 3) +
geom_errorbar(aes(ymin = mean_freq_oft - se_oft, ymax = mean_freq_oft + se_oft), width = 0.2) +
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft[syllable_order]) + # Optional: reorder labels if needed
labs(
x = "Syllables (Ordered by Control Frequency)",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0))
)
plot_oft_3
#ggsave("oft_graph_3.png", plot = plot_oft_3, width = 10, height = 6) #makes spaces visible
#load results file and make sure headings and levels are established
df_nor <- read.csv("new_moseq_NOR_stats.csv", header=TRUE)
df_nor$syllable <- factor(df_nor$syllable) # Convert to categorical
df_nor$group <- factor(df_nor$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
df_nor$ID <- factor(df_nor$ID)
#model_simple <- lm(frequency ~ group * syllable, data = df_oft) #removed repeated measures random variance, still works
#summary(model_simple)
#or
model_nor <- lmer(frequency ~ group * syllable + (1 | ID), data = df_nor)
boundary (singular) fit: see help('isSingular')
summary(model_nor)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_nor
REML criterion at convergence: -5346
Scaled residuals:
Min 1Q Median 3Q Max
-3.809 -0.448 -0.097 0.425 4.619
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.000000 0.000
Residual 0.000786 0.028
Number of obs: 1352, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 1.41e-01 5.50e-03 1.29e+03 25.57 < 2e-16 ***
grouppost_w1 1.50e-02 7.78e-03 1.29e+03 1.92 0.05479 .
grouppost_w2 2.15e-02 8.12e-03 1.29e+03 2.64 0.00833 **
syllable1 2.81e-02 7.78e-03 1.29e+03 3.62 0.00031 ***
syllable2 3.00e-03 7.78e-03 1.29e+03 0.39 0.69982
syllable3 -8.05e-02 7.78e-03 1.29e+03 -10.36 < 2e-16 ***
syllable4 -7.66e-02 7.86e-03 1.29e+03 -9.75 < 2e-16 ***
syllable5 -4.61e-02 7.78e-03 1.29e+03 -5.92 4.0e-09 ***
syllable6 -9.10e-02 7.78e-03 1.29e+03 -11.70 < 2e-16 ***
syllable7 -9.36e-02 7.78e-03 1.29e+03 -12.03 < 2e-16 ***
syllable8 -1.25e-01 7.94e-03 1.29e+03 -15.71 < 2e-16 ***
syllable9 -1.21e-01 8.75e-03 1.29e+03 -13.83 < 2e-16 ***
syllable10 -1.24e-01 8.12e-03 1.29e+03 -15.31 < 2e-16 ***
syllable11 -1.24e-01 8.03e-03 1.29e+03 -15.43 < 2e-16 ***
syllable12 -1.27e-01 9.79e-03 1.29e+03 -13.00 < 2e-16 ***
syllable13 -1.29e-01 8.91e-03 1.29e+03 -14.47 < 2e-16 ***
syllable14 -1.25e-01 1.01e-02 1.29e+03 -12.36 < 2e-16 ***
syllable15 -1.03e-01 8.23e-03 1.29e+03 -12.47 < 2e-16 ***
syllable16 -1.20e-01 7.78e-03 1.29e+03 -15.37 < 2e-16 ***
syllable17 -1.30e-01 8.12e-03 1.29e+03 -15.96 < 2e-16 ***
syllable18 -1.18e-01 8.75e-03 1.29e+03 -13.47 < 2e-16 ***
syllable19 -1.30e-01 1.08e-02 1.29e+03 -11.97 < 2e-16 ***
syllable20 -1.12e-01 8.34e-03 1.29e+03 -13.48 < 2e-16 ***
syllable21 -1.19e-01 8.12e-03 1.29e+03 -14.64 < 2e-16 ***
grouppost_w1:syllable1 -8.04e-03 1.10e-02 1.29e+03 -0.73 0.46480
grouppost_w2:syllable1 -9.45e-02 1.15e-02 1.29e+03 -8.22 4.8e-16 ***
grouppost_w1:syllable2 -5.14e-02 1.10e-02 1.29e+03 -4.67 3.3e-06 ***
grouppost_w2:syllable2 -1.32e-01 1.16e-02 1.29e+03 -11.37 < 2e-16 ***
grouppost_w1:syllable3 2.53e-03 1.10e-02 1.29e+03 0.23 0.81782
grouppost_w2:syllable3 3.88e-02 1.15e-02 1.29e+03 3.38 0.00075 ***
grouppost_w1:syllable4 5.52e-03 1.11e-02 1.29e+03 0.50 0.61757
grouppost_w2:syllable4 2.54e-02 1.15e-02 1.29e+03 2.20 0.02803 *
grouppost_w1:syllable5 -8.30e-03 1.10e-02 1.29e+03 -0.75 0.45063
grouppost_w2:syllable5 -4.32e-02 1.15e-02 1.29e+03 -3.76 0.00018 ***
grouppost_w1:syllable6 -6.90e-03 1.10e-02 1.29e+03 -0.63 0.53082
grouppost_w2:syllable6 -4.38e-02 1.15e-02 1.29e+03 -3.81 0.00014 ***
grouppost_w1:syllable7 -1.51e-02 1.10e-02 1.29e+03 -1.38 0.16900
grouppost_w2:syllable7 -3.69e-02 1.15e-02 1.29e+03 -3.21 0.00135 **
grouppost_w1:syllable8 -1.25e-02 1.13e-02 1.29e+03 -1.11 0.26898
grouppost_w2:syllable8 1.27e-02 1.16e-02 1.29e+03 1.10 0.27332
grouppost_w1:syllable9 -1.72e-02 1.19e-02 1.29e+03 -1.44 0.14982
grouppost_w2:syllable9 1.54e-02 1.22e-02 1.29e+03 1.25 0.20978
grouppost_w1:syllable10 -8.35e-03 1.14e-02 1.29e+03 -0.73 0.46501
grouppost_w2:syllable10 6.10e-03 1.17e-02 1.29e+03 0.52 0.60318
grouppost_w1:syllable11 -1.40e-02 1.14e-02 1.29e+03 -1.23 0.21908
grouppost_w2:syllable11 -2.40e-02 1.17e-02 1.29e+03 -2.04 0.04133 *
grouppost_w1:syllable12 -1.18e-02 1.30e-02 1.29e+03 -0.91 0.36513
grouppost_w2:syllable12 8.88e-04 1.31e-02 1.29e+03 0.07 0.94584
grouppost_w1:syllable13 -3.62e-03 1.25e-02 1.29e+03 -0.29 0.77220
grouppost_w2:syllable13 -2.64e-03 1.24e-02 1.29e+03 -0.21 0.83083
grouppost_w1:syllable14 -2.06e-02 1.35e-02 1.29e+03 -1.53 0.12616
grouppost_w2:syllable14 -5.51e-04 1.34e-02 1.29e+03 -0.04 0.96712
grouppost_w1:syllable15 -3.19e-02 1.23e-02 1.29e+03 -2.60 0.00947 **
grouppost_w2:syllable15 -3.69e-02 1.26e-02 1.29e+03 -2.92 0.00360 **
grouppost_w1:syllable16 -1.56e-02 1.11e-02 1.29e+03 -1.40 0.16078
grouppost_w2:syllable16 -3.03e-02 1.23e-02 1.29e+03 -2.46 0.01414 *
grouppost_w1:syllable17 -1.03e-02 1.14e-02 1.29e+03 -0.90 0.36827
grouppost_w2:syllable17 -2.30e-02 1.20e-02 1.29e+03 -1.92 0.05460 .
grouppost_w1:syllable18 -2.75e-02 1.24e-02 1.29e+03 -2.22 0.02638 *
grouppost_w2:syllable18 -3.81e-02 1.56e-02 1.29e+03 -2.44 0.01477 *
grouppost_w1:syllable19 -1.75e-02 1.46e-02 1.29e+03 -1.19 0.23234
grouppost_w2:syllable19 -8.47e-03 1.43e-02 1.29e+03 -0.59 0.55502
grouppost_w1:syllable20 -2.95e-02 1.22e-02 1.29e+03 -2.42 0.01563 *
grouppost_w2:syllable20 -3.60e-02 1.23e-02 1.29e+03 -2.93 0.00350 **
grouppost_w1:syllable21 -2.10e-02 1.27e-02 1.29e+03 -1.65 0.09970 .
grouppost_w2:syllable21 -3.37e-02 1.41e-02 1.29e+03 -2.39 0.01719 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 66 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#assumption check 1 - Normality of residuals (should be normally distributed) - passes
qqnorm(resid(model_nor))
qqline(resid(model_nor))
#probs a lil' bit non-normal, thus, whe calculating confidence intervals, used "boot" method which assumes non-normality
hist(resid(model_nor))
#Assumption 2 - Homoscedasticity (variance should be consistent) - passes
plot(fitted(model_nor), resid(model_nor))
#violates it, not evenly distributed, thus, Heteroscedasticity
#Assumption 3 - confidence intervals - passes
confint(model_nor, method = "boot")
Computing bootstrap confidence intervals ...
239 message(s): boundary (singular) fit: see help('isSingular')
2.5 % 97.5 %
.sig01 0.000000 0.002755
.sigma 0.026893 0.029150
(Intercept) 0.130199 0.151306
grouppost_w1 -0.000311 0.029029
grouppost_w2 0.005524 0.035847
syllable1 0.011919 0.043326
syllable2 -0.013069 0.016687
syllable3 -0.095610 -0.066037
syllable4 -0.091390 -0.063206
syllable5 -0.062163 -0.030707
syllable6 -0.106358 -0.076601
syllable7 -0.108868 -0.078577
syllable8 -0.140468 -0.111578
syllable9 -0.136593 -0.104360
syllable10 -0.140537 -0.107686
syllable11 -0.138914 -0.108772
syllable12 -0.145916 -0.109804
syllable13 -0.146810 -0.111959
syllable14 -0.144155 -0.103832
syllable15 -0.120732 -0.087235
syllable16 -0.133439 -0.106136
syllable17 -0.146278 -0.111239
syllable18 -0.134728 -0.099431
syllable19 -0.151196 -0.108496
syllable20 -0.129711 -0.097217
syllable21 -0.135040 -0.103652
grouppost_w1:syllable1 -0.030664 0.014068
grouppost_w2:syllable1 -0.116015 -0.070720
grouppost_w1:syllable2 -0.071555 -0.028493
grouppost_w2:syllable2 -0.155335 -0.108496
grouppost_w1:syllable3 -0.020379 0.023325
grouppost_w2:syllable3 0.018378 0.062881
grouppost_w1:syllable4 -0.014968 0.030819
grouppost_w2:syllable4 0.006061 0.046673
grouppost_w1:syllable5 -0.029258 0.013955
grouppost_w2:syllable5 -0.063904 -0.018751
grouppost_w1:syllable6 -0.028685 0.015049
grouppost_w2:syllable6 -0.064157 -0.022687
grouppost_w1:syllable7 -0.035181 0.006085
grouppost_w2:syllable7 -0.058638 -0.014285
grouppost_w1:syllable8 -0.031997 0.007183
grouppost_w2:syllable8 -0.009184 0.035945
grouppost_w1:syllable9 -0.039266 0.005912
grouppost_w2:syllable9 -0.008254 0.040934
grouppost_w1:syllable10 -0.030515 0.015995
grouppost_w2:syllable10 -0.017615 0.028575
grouppost_w1:syllable11 -0.036521 0.009172
grouppost_w2:syllable11 -0.046390 -0.001053
grouppost_w1:syllable12 -0.036836 0.014468
grouppost_w2:syllable12 -0.023771 0.026844
grouppost_w1:syllable13 -0.024788 0.020922
grouppost_w2:syllable13 -0.024759 0.021527
grouppost_w1:syllable14 -0.046803 0.007979
grouppost_w2:syllable14 -0.027263 0.026366
grouppost_w1:syllable15 -0.053033 -0.004707
grouppost_w2:syllable15 -0.059677 -0.011931
grouppost_w1:syllable16 -0.035266 0.005818
grouppost_w2:syllable16 -0.054333 -0.007769
grouppost_w1:syllable17 -0.032123 0.013068
grouppost_w2:syllable17 -0.047916 0.000608
grouppost_w1:syllable18 -0.051827 -0.002216
grouppost_w2:syllable18 -0.067731 -0.006439
grouppost_w1:syllable19 -0.044919 0.011216
grouppost_w2:syllable19 -0.034213 0.022045
grouppost_w1:syllable20 -0.051975 -0.005634
grouppost_w2:syllable20 -0.058936 -0.013813
grouppost_w1:syllable21 -0.044932 0.004865
grouppost_w2:syllable21 -0.061235 -0.004343
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
# Obtain estimated marginal means
emm_nor <- emmeans(model_nor, ~ group | syllable) # Pairwise comparisons of syllable effects within each group (groupwise effects for each syllable)
head(emm_nor)
group syllable emmean SE df lower.CL upper.CL
control 0 0.1407 0.00550 1272 0.130 0.151
post_w1 0 0.1556 0.00550 1272 0.145 0.166
post_w2 0 0.1621 0.00598 1272 0.150 0.174
control 1 0.1688 0.00550 1272 0.158 0.180
post_w1 1 0.1757 0.00550 1272 0.165 0.186
post_w2 1 0.0958 0.00598 1272 0.084 0.107
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_nor <- contrast(emm_nor, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm
summary(pairwise_nor)
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0150 0.00778 1274 -1.920 0.1330
control - post_w2 -0.0215 0.00813 1278 -2.640 0.0230
post_w1 - post_w2 -0.0065 0.00813 1278 -0.800 0.7020
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0069 0.00778 1274 -0.890 0.6480
control - post_w2 0.0730 0.00813 1278 8.990 <.0001
post_w1 - post_w2 0.0799 0.00813 1278 9.840 <.0001
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0365 0.00778 1274 4.690 <.0001
control - post_w2 0.1100 0.00823 1278 13.370 <.0001
post_w1 - post_w2 0.0736 0.00823 1278 8.940 <.0001
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0175 0.00778 1274 -2.250 0.0640
control - post_w2 -0.0603 0.00813 1278 -7.420 <.0001
post_w1 - post_w2 -0.0428 0.00813 1278 -5.270 <.0001
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0205 0.00786 1275 -2.610 0.0250
control - post_w2 -0.0469 0.00820 1278 -5.710 <.0001
post_w1 - post_w2 -0.0264 0.00813 1278 -3.250 0.0030
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0067 0.00778 1274 -0.860 0.6690
control - post_w2 0.0217 0.00813 1278 2.670 0.0210
post_w1 - post_w2 0.0284 0.00813 1278 3.490 0.0010
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0081 0.00778 1274 -1.040 0.5540
control - post_w2 0.0223 0.00813 1278 2.750 0.0170
post_w1 - post_w2 0.0304 0.00813 1278 3.740 0.0010
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0002 0.00778 1274 0.020 1.0000
control - post_w2 0.0154 0.00813 1278 1.900 0.1390
post_w1 - post_w2 0.0152 0.00813 1278 1.880 0.1460
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0025 0.00818 1276 -0.300 0.9510
control - post_w2 -0.0342 0.00828 1279 -4.130 <.0001
post_w1 - post_w2 -0.0317 0.00837 1279 -3.790 <.0001
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0023 0.00906 1279 0.250 0.9670
control - post_w2 -0.0368 0.00915 1281 -4.020 <.0001
post_w1 - post_w2 -0.0391 0.00856 1280 -4.570 <.0001
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0066 0.00836 1277 -0.790 0.7090
control - post_w2 -0.0276 0.00846 1278 -3.260 0.0030
post_w1 - post_w2 -0.0210 0.00836 1276 -2.510 0.0330
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0010 0.00827 1276 -0.120 0.9920
control - post_w2 0.0025 0.00847 1278 0.290 0.9530
post_w1 - post_w2 0.0035 0.00847 1278 0.410 0.9110
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0031 0.01050 1285 -0.300 0.9510
control - post_w2 -0.0224 0.01020 1284 -2.180 0.0750
post_w1 - post_w2 -0.0192 0.00912 1284 -2.110 0.0890
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0113 0.00977 1281 -1.160 0.4770
control - post_w2 -0.0188 0.00931 1279 -2.020 0.1070
post_w1 - post_w2 -0.0075 0.00915 1282 -0.820 0.6920
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0056 0.01100 1282 0.510 0.8650
control - post_w2 -0.0209 0.01060 1279 -1.970 0.1210
post_w1 - post_w2 -0.0266 0.00952 1284 -2.790 0.0150
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0169 0.00948 1279 1.780 0.1760
control - post_w2 0.0154 0.00968 1282 1.590 0.2510
post_w1 - post_w2 -0.0015 0.01040 1283 -0.150 0.9880
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0006 0.00794 1275 0.080 0.9960
control - post_w2 0.0089 0.00930 1281 0.950 0.6060
post_w1 - post_w2 0.0082 0.00944 1281 0.870 0.6580
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0047 0.00837 1278 -0.560 0.8420
control - post_w2 0.0016 0.00879 1280 0.180 0.9830
post_w1 - post_w2 0.0062 0.00870 1279 0.720 0.7540
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0125 0.00962 1277 1.300 0.3930
control - post_w2 0.0166 0.01330 1284 1.250 0.4260
post_w1 - post_w2 0.0041 0.01330 1283 0.310 0.9500
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0025 0.01240 1285 0.200 0.9780
control - post_w2 -0.0130 0.01180 1282 -1.100 0.5150
post_w1 - post_w2 -0.0155 0.01090 1281 -1.430 0.3280
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0146 0.00941 1280 1.550 0.2680
control - post_w2 0.0146 0.00926 1283 1.570 0.2580
post_w1 - post_w2 0.0000 0.00977 1282 0.000 1.0000
syllable = 21:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0060 0.01010 1281 0.600 0.8220
control - post_w2 0.0123 0.01160 1284 1.060 0.5400
post_w1 - post_w2 0.0063 0.01280 1285 0.490 0.8760
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
#this data will be used for plotting
# Convert the pairwise results into a data frame using summary
pairwise_results_nor <- summary(pairwise_nor)
# Filter significant results (p-value < 0.05)
sig_results_nor <- pairwise_results_nor[pairwise_results_nor$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_nor <- sig_results_nor %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
# Print sig_syllables to check
print(sig_syllables_nor)
#for ggplot below
syllable_labels_nor <-c(
"0" = "0 (rear_supported)",
"1" = "1 (sniff)",
"2" = "2 (stand-still)",
"3" = "3 (turn_left_moderate)",
"4" = "4 (turn_right_moderate)",
"5" = "5 (sniff_object)",
"6" = "6 (turn_right_sharp)",
"7" = "7 (turn_left_sharp)",
"8" = "8 (acceleration_left)",
"9" = "9 (rear_supported_left_traverse)",
"10" = "10 (acceleration_right)",
"11" = "11 (locomotion_sniff)",
"12" = "12 (thigmotaxsis_right)",
"13" = "13 (rear_supported_multiple)",
"14" = "14 (rear_supported_right_traverse)",
"15" = "15 (sniff_up)",
"16" = "16 (spin_left)",
"17" = "17 (sniff_down)",
"18" = "18 (hunch)",
"19" = "19 (thigmotaxsis_left)",
"20" = "20 (groom_jump_object)",
"21" = "21 (groom_curl)",
"22" = "22 (thigmotaxsis_walk)"
)
# Calculate means by syllable and group
nor_means <- df_nor %>%
group_by(syllable, group) %>%
summarize(
mean_freq_nor = mean(frequency, na.rm = TRUE),
se_nor = sd(frequency, na.rm = TRUE)/sqrt(n())
)
`summarise()` has grouped output by 'syllable'. You can override using the `.groups` argument.
# Create the plot
plot_nor <- ggplot(nor_means, aes(x = syllable, y = mean_freq_nor, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = mean_freq_nor - se_nor, ymax = mean_freq_nor + se_nor), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_nor) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_nor <- plot_nor + geom_text(
data = sig_syllables_nor,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_nor
#ggsave("nor_graph.png", plot = plot_nor, width = 10, height = 6) #makes spaces visible
#load results file and make sure headings and levels are established
df_epm <- read.csv("new_moseq_EPM_stats.csv", header=TRUE)
df_epm$syllable <- factor(df_epm$syllable) # Convert to categorical
df_epm$group <- factor(df_epm$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
df_epm$ID <- factor(df_epm$ID)
model_epm <- lmer(frequency ~ group * syllable + (1 | ID), data = df_epm)
boundary (singular) fit: see help('isSingular')
summary(model_epm)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_epm
REML criterion at convergence: -3596
Scaled residuals:
Min 1Q Median 3Q Max
-4.379 -0.453 -0.087 0.409 4.993
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.000000 0.0000
Residual 0.000247 0.0157
Number of obs: 749, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 0.18844 0.00436 686.00000 43.25 < 2e-16 ***
grouppost_w1 -0.01206 0.00616 686.00000 -1.96 0.0506 .
grouppost_w2 0.00167 0.00661 686.00000 0.25 0.8002
syllable1 -0.05539 0.00616 686.00000 -8.99 < 2e-16 ***
syllable2 -0.07444 0.00616 686.00000 -12.08 < 2e-16 ***
syllable3 -0.07917 0.00616 686.00000 -12.85 < 2e-16 ***
syllable4 -0.11268 0.00616 686.00000 -18.29 < 2e-16 ***
syllable5 -0.13817 0.00616 686.00000 -22.42 < 2e-16 ***
syllable6 -0.14310 0.00616 686.00000 -23.22 < 2e-16 ***
syllable7 -0.14838 0.00616 686.00000 -24.08 < 2e-16 ***
syllable8 -0.15572 0.00616 686.00000 -25.27 < 2e-16 ***
syllable9 -0.16224 0.00616 686.00000 -26.33 < 2e-16 ***
syllable10 -0.17150 0.00616 686.00000 -27.83 < 2e-16 ***
syllable11 -0.16992 0.00616 686.00000 -27.58 < 2e-16 ***
syllable12 -0.17126 0.00616 686.00000 -27.79 < 2e-16 ***
syllable13 -0.16289 0.00616 686.00000 -26.43 < 2e-16 ***
syllable14 -0.17793 0.00616 686.00000 -28.87 < 2e-16 ***
syllable15 -0.17251 0.00616 686.00000 -27.99 < 2e-16 ***
syllable16 -0.18153 0.00616 686.00000 -29.46 < 2e-16 ***
syllable17 -0.18310 0.00629 686.00000 -29.11 < 2e-16 ***
syllable18 -0.17784 0.00616 686.00000 -28.86 < 2e-16 ***
syllable19 -0.18124 0.00616 686.00000 -29.41 < 2e-16 ***
syllable20 -0.18330 0.00616 686.00000 -29.75 < 2e-16 ***
grouppost_w1:syllable1 0.00457 0.00871 686.00000 0.52 0.6001
grouppost_w2:syllable1 -0.01807 0.00935 686.00000 -1.93 0.0536 .
grouppost_w1:syllable2 0.00154 0.00871 686.00000 0.18 0.8594
grouppost_w2:syllable2 -0.00898 0.00935 686.00000 -0.96 0.3369
grouppost_w1:syllable3 0.00410 0.00871 686.00000 0.47 0.6381
grouppost_w2:syllable3 0.00265 0.00935 686.00000 0.28 0.7764
grouppost_w1:syllable4 0.03753 0.00871 686.00000 4.31 1.9e-05 ***
grouppost_w2:syllable4 -0.00325 0.00935 686.00000 -0.35 0.7284
grouppost_w1:syllable5 0.00946 0.00871 686.00000 1.09 0.2780
grouppost_w2:syllable5 0.00910 0.00935 686.00000 0.97 0.3304
grouppost_w1:syllable6 0.01767 0.00871 686.00000 2.03 0.0430 *
grouppost_w2:syllable6 -0.01212 0.00935 686.00000 -1.30 0.1950
grouppost_w1:syllable7 0.02261 0.00871 686.00000 2.59 0.0097 **
grouppost_w2:syllable7 -0.00398 0.00935 686.00000 -0.43 0.6705
grouppost_w1:syllable8 0.01043 0.00871 686.00000 1.20 0.2317
grouppost_w2:syllable8 0.01095 0.00935 686.00000 1.17 0.2418
grouppost_w1:syllable9 0.01134 0.00871 686.00000 1.30 0.1936
grouppost_w2:syllable9 -0.00541 0.00935 686.00000 -0.58 0.5626
grouppost_w1:syllable10 0.02283 0.00871 686.00000 2.62 0.0090 **
grouppost_w2:syllable10 0.00717 0.00935 686.00000 0.77 0.4434
grouppost_w1:syllable11 0.02044 0.00871 686.00000 2.35 0.0193 *
grouppost_w2:syllable11 -0.00406 0.00935 686.00000 -0.43 0.6640
grouppost_w1:syllable12 0.01497 0.00871 686.00000 1.72 0.0864 .
grouppost_w2:syllable12 0.00376 0.00935 686.00000 0.40 0.6879
grouppost_w1:syllable13 0.00351 0.00871 686.00000 0.40 0.6877
grouppost_w2:syllable13 -0.01367 0.00935 686.00000 -1.46 0.1439
grouppost_w1:syllable14 0.00999 0.00871 686.00000 1.15 0.2518
grouppost_w2:syllable14 0.01434 0.00935 686.00000 1.53 0.1254
grouppost_w1:syllable15 0.00702 0.00871 686.00000 0.81 0.4207
grouppost_w2:syllable15 -0.00311 0.00935 686.00000 -0.33 0.7392
grouppost_w1:syllable16 0.01074 0.00871 686.00000 1.23 0.2182
grouppost_w2:syllable16 0.00203 0.00935 686.00000 0.22 0.8278
grouppost_w1:syllable17 0.01468 0.00881 686.00000 1.67 0.0960 .
grouppost_w2:syllable17 0.00001 0.00957 686.00000 0.00 0.9992
grouppost_w1:syllable18 0.00703 0.00871 686.00000 0.81 0.4202
grouppost_w2:syllable18 -0.00766 0.00967 686.00000 -0.79 0.4287
grouppost_w1:syllable19 0.00942 0.00891 686.00000 1.06 0.2909
grouppost_w2:syllable19 -0.00089 0.00949 686.00000 -0.09 0.9253
grouppost_w1:syllable20 0.01214 0.00871 686.00000 1.39 0.1641
grouppost_w2:syllable20 0.00015 0.00935 686.00000 0.02 0.9872
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 63 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#assumption check 1 - Normality of residuals (should be normally distributed) - passes
qqnorm(resid(model_epm))
qqline(resid(model_epm))
#probs a lil' bit non-normal, thus, whe calculating confidence intervals, used "boot" method which assumes non-normality
#Assumption 2 - Homoscedasticity (variance should be consistent) - passes
plot(fitted(model_epm), resid(model_epm))
#violates it, not evenly distributed, thus, Heteroscedasticity
hist(resid(model_epm))
#Assumption 3 - confidence intervals - passes
confint(model_epm, method = "boot")
Computing bootstrap confidence intervals ...
291 message(s): boundary (singular) fit: see help('isSingular')
2.5 % 97.5 %
.sig01 0.000000 0.002065
.sigma 0.014909 0.016478
(Intercept) 0.179353 0.196656
grouppost_w1 -0.023602 -0.000858
grouppost_w2 -0.012016 0.014334
syllable1 -0.068320 -0.043664
syllable2 -0.085778 -0.061551
syllable3 -0.090848 -0.067044
syllable4 -0.123691 -0.099491
syllable5 -0.150773 -0.125928
syllable6 -0.156651 -0.130360
syllable7 -0.160876 -0.136478
syllable8 -0.167064 -0.143592
syllable9 -0.173378 -0.149489
syllable10 -0.183510 -0.160225
syllable11 -0.182048 -0.158165
syllable12 -0.183846 -0.159587
syllable13 -0.173932 -0.150715
syllable14 -0.189248 -0.166468
syllable15 -0.184363 -0.160250
syllable16 -0.193997 -0.169289
syllable17 -0.196341 -0.170517
syllable18 -0.189670 -0.163810
syllable19 -0.192386 -0.167669
syllable20 -0.194555 -0.171826
grouppost_w1:syllable1 -0.012245 0.022272
grouppost_w2:syllable1 -0.036405 0.000221
grouppost_w1:syllable2 -0.016881 0.019139
grouppost_w2:syllable2 -0.026427 0.010231
grouppost_w1:syllable3 -0.011714 0.021700
grouppost_w2:syllable3 -0.015224 0.021124
grouppost_w1:syllable4 0.020846 0.053894
grouppost_w2:syllable4 -0.021867 0.013653
grouppost_w1:syllable5 -0.007963 0.026526
grouppost_w2:syllable5 -0.008290 0.027857
grouppost_w1:syllable6 0.000233 0.035573
grouppost_w2:syllable6 -0.030902 0.007193
grouppost_w1:syllable7 0.004235 0.039410
grouppost_w2:syllable7 -0.021972 0.016032
grouppost_w1:syllable8 -0.006589 0.026736
grouppost_w2:syllable8 -0.006365 0.030027
grouppost_w1:syllable9 -0.006086 0.028771
grouppost_w2:syllable9 -0.023416 0.013530
grouppost_w1:syllable10 0.005326 0.040741
grouppost_w2:syllable10 -0.009381 0.024179
grouppost_w1:syllable11 0.004779 0.038271
grouppost_w2:syllable11 -0.021867 0.013724
grouppost_w1:syllable12 -0.003207 0.031057
grouppost_w2:syllable12 -0.014456 0.023336
grouppost_w1:syllable13 -0.011768 0.020773
grouppost_w2:syllable13 -0.032485 0.005628
grouppost_w1:syllable14 -0.006505 0.027177
grouppost_w2:syllable14 -0.004641 0.032444
grouppost_w1:syllable15 -0.009766 0.025030
grouppost_w2:syllable15 -0.020761 0.016228
grouppost_w1:syllable16 -0.006804 0.028709
grouppost_w2:syllable16 -0.015220 0.020273
grouppost_w1:syllable17 -0.003435 0.032125
grouppost_w2:syllable17 -0.019789 0.018155
grouppost_w1:syllable18 -0.011000 0.025123
grouppost_w2:syllable18 -0.027300 0.011608
grouppost_w1:syllable19 -0.009414 0.026810
grouppost_w2:syllable19 -0.020038 0.019357
grouppost_w1:syllable20 -0.003513 0.029652
grouppost_w2:syllable20 -0.017720 0.018753
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
# Obtain estimated marginal means
emm_epm <- emmeans(model_epm, ~ group | syllable) # Pairwise comparisons of syllable effects within each group (groupwise effects for each syllable)
head(emm_epm)
group syllable emmean SE df lower.CL upper.CL
control 0 0.188 0.00436 686 0.180 0.197
post_w1 0 0.176 0.00436 686 0.168 0.185
post_w2 0 0.190 0.00497 686 0.180 0.200
control 1 0.133 0.00436 686 0.124 0.142
post_w1 1 0.126 0.00436 686 0.117 0.134
post_w2 1 0.117 0.00497 686 0.107 0.126
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_epm <- contrast(emm_epm, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm
summary(pairwise_epm)
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 0.01206 0.00616 674 1.960 0.1240
control - post_w2 -0.00167 0.00661 677 -0.250 0.9650
post_w1 - post_w2 -0.01374 0.00661 677 -2.080 0.0950
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00749 0.00616 674 1.220 0.4440
control - post_w2 0.01639 0.00661 677 2.480 0.0360
post_w1 - post_w2 0.00890 0.00661 677 1.350 0.3700
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 0.01052 0.00616 674 1.710 0.2030
control - post_w2 0.00731 0.00661 677 1.110 0.5110
post_w1 - post_w2 -0.00321 0.00661 677 -0.490 0.8780
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00796 0.00616 674 1.290 0.4000
control - post_w2 -0.00433 0.00661 677 -0.650 0.7900
post_w1 - post_w2 -0.01229 0.00661 677 -1.860 0.1510
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.02546 0.00616 674 -4.130 <.0001
control - post_w2 0.00157 0.00661 677 0.240 0.9690
post_w1 - post_w2 0.02703 0.00661 677 4.090 <.0001
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00260 0.00616 674 0.420 0.9060
control - post_w2 -0.01077 0.00661 677 -1.630 0.2340
post_w1 - post_w2 -0.01338 0.00661 677 -2.020 0.1070
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00560 0.00616 674 -0.910 0.6350
control - post_w2 0.01045 0.00661 677 1.580 0.2550
post_w1 - post_w2 0.01605 0.00661 677 2.430 0.0410
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.01055 0.00616 674 -1.710 0.2020
control - post_w2 0.00230 0.00661 677 0.350 0.9350
post_w1 - post_w2 0.01285 0.00661 677 1.940 0.1270
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00163 0.00616 674 0.260 0.9620
control - post_w2 -0.01262 0.00661 677 -1.910 0.1370
post_w1 - post_w2 -0.01425 0.00661 677 -2.160 0.0800
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00072 0.00616 674 0.120 0.9920
control - post_w2 0.00374 0.00661 677 0.570 0.8380
post_w1 - post_w2 0.00302 0.00661 677 0.460 0.8920
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.01076 0.00616 674 -1.750 0.1890
control - post_w2 -0.00884 0.00661 677 -1.340 0.3750
post_w1 - post_w2 0.00192 0.00661 677 0.290 0.9540
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00837 0.00616 674 -1.360 0.3630
control - post_w2 0.00239 0.00661 677 0.360 0.9310
post_w1 - post_w2 0.01076 0.00661 677 1.630 0.2340
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00290 0.00616 674 -0.470 0.8850
control - post_w2 -0.00543 0.00661 677 -0.820 0.6900
post_w1 - post_w2 -0.00253 0.00661 677 -0.380 0.9230
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00856 0.00616 674 1.390 0.3470
control - post_w2 0.01200 0.00661 677 1.820 0.1650
post_w1 - post_w2 0.00344 0.00661 677 0.520 0.8610
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00207 0.00616 674 0.340 0.9400
control - post_w2 -0.01601 0.00661 677 -2.420 0.0410
post_w1 - post_w2 -0.01808 0.00661 677 -2.740 0.0180
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00504 0.00616 674 0.820 0.6920
control - post_w2 0.00144 0.00661 677 0.220 0.9740
post_w1 - post_w2 -0.00360 0.00661 677 -0.550 0.8490
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00133 0.00616 674 0.220 0.9750
control - post_w2 -0.00371 0.00661 677 -0.560 0.8410
post_w1 - post_w2 -0.00503 0.00661 677 -0.760 0.7270
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00261 0.00629 675 -0.420 0.9090
control - post_w2 -0.00168 0.00693 677 -0.240 0.9680
post_w1 - post_w2 0.00093 0.00682 678 0.140 0.9900
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00504 0.00616 674 0.820 0.6920
control - post_w2 0.00598 0.00706 679 0.850 0.6740
post_w1 - post_w2 0.00095 0.00706 679 0.130 0.9900
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00265 0.00644 676 0.410 0.9110
control - post_w2 -0.00078 0.00682 678 -0.110 0.9930
post_w1 - post_w2 -0.00343 0.00707 678 -0.490 0.8780
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00007 0.00616 674 -0.010 1.0000
control - post_w2 -0.00182 0.00661 677 -0.280 0.9590
post_w1 - post_w2 -0.00175 0.00661 677 -0.260 0.9620
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
#this data will be used for plotting
# Convert the pairwise results into a data frame using summary
pairwise_results_epm <- summary(pairwise_epm)
# Filter significant results (p-value < 0.05)
sig_results_epm <- pairwise_results_epm[pairwise_results_epm$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_epm <- sig_results_epm %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
# Print sig_syllables to check
print(sig_syllables_epm)
syllable_labels_epm <- c(
"0" = "0 (stationary_sniff)",
"1" = "1 (stationary_tilt)",
"2" = "2 (sniff_right)",
"3" = "3 (groom_hunch)",
"4" = "4 (sniff_left)",
"5" = "5 (turn_left_sharp)",
"6" = "6 (sniff_forwards)",
"7" = "7 (rear_supported/groom)",
"8" = "8 (locomotion_brief)",
"9" = "9 (rear_supported)",
"10" = "10 (locomotion_tilt)",
"11" = "11 (accelerate_forward)",
"12" = "12 (sniff_junction)",
"13" = "13 (rear_supported_twist)",
"14" = "14 (turn_left_stationary)",
"15" = "15 (turn_right_stationary)",
"16" = "16 (rear_supported)",
"17" = "17 (rear_supported)"
)
# Calculate means by syllable and group
epm_means <- df_epm %>%
group_by(syllable, group) %>%
summarize(
mean_freq_epm = mean(frequency, na.rm = TRUE),
se_epm = sd(frequency, na.rm = TRUE)/sqrt(n())
)
`summarise()` has grouped output by 'syllable'. You can override using the `.groups` argument.
# Create the plot
plot_epm <- ggplot(epm_means, aes(x = syllable, y = mean_freq_epm, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = mean_freq_epm - se_epm, ymax = mean_freq_epm + se_epm), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_epm) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_epm <- plot_epm + geom_text(
data = sig_syllables_epm,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_epm
#ggsave("epm_graph.png", plot = plot_epm, width = 10, height = 6) #makes spaces visible
#load results file and make sure headings and levels are established
df_3ct <- read.csv("new_moseq_3CT_stats.csv", header=TRUE)
df_3ct$syllable <- factor(df_3ct$syllable) # Convert to categorical
df_3ct$group <- factor(df_3ct$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
df_3ct$ID <- factor(df_3ct$ID)
model_3ct <- lmer(frequency ~ group * syllable + (1 | ID), data = df_3ct)
boundary (singular) fit: see help('isSingular')
summary(model_3ct)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_3ct
REML criterion at convergence: -23662
Scaled residuals:
Min 1Q Median 3Q Max
-4.784 -0.480 -0.094 0.419 9.838
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.00000 0.0000
Residual 0.00016 0.0127
Number of obs: 4219, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 8.37e-02 2.03e-03 4.09e+03 41.26 < 2e-16 ***
grouppost_w1 -1.99e-02 2.87e-03 4.09e+03 -6.95 4.3e-12 ***
grouppost_w2 -3.96e-03 3.29e-03 4.09e+03 -1.21 0.22794
syllable1 5.25e-03 2.87e-03 4.09e+03 1.83 0.06705 .
syllable2 -4.86e-02 2.87e-03 4.09e+03 -16.96 < 2e-16 ***
syllable3 -4.35e-02 2.87e-03 4.09e+03 -15.17 < 2e-16 ***
syllable4 -3.76e-02 2.87e-03 4.09e+03 -13.10 < 2e-16 ***
syllable5 -4.69e-02 2.87e-03 4.09e+03 -16.36 < 2e-16 ***
syllable6 -5.47e-02 2.89e-03 4.09e+03 -18.94 < 2e-16 ***
syllable7 -4.92e-02 2.87e-03 4.09e+03 -17.15 < 2e-16 ***
syllable8 -5.17e-02 2.87e-03 4.09e+03 -18.02 < 2e-16 ***
syllable9 -5.09e-02 2.87e-03 4.09e+03 -17.74 < 2e-16 ***
syllable10 -5.47e-02 2.87e-03 4.09e+03 -19.09 < 2e-16 ***
syllable11 -6.09e-02 2.87e-03 4.09e+03 -21.25 < 2e-16 ***
syllable12 -5.91e-02 2.87e-03 4.09e+03 -20.62 < 2e-16 ***
syllable13 -5.29e-02 2.87e-03 4.09e+03 -18.45 < 2e-16 ***
syllable14 -5.82e-02 2.87e-03 4.09e+03 -20.29 < 2e-16 ***
syllable15 -6.00e-02 2.87e-03 4.09e+03 -20.92 < 2e-16 ***
syllable16 -6.28e-02 2.89e-03 4.09e+03 -21.77 < 2e-16 ***
syllable17 -5.75e-02 2.87e-03 4.09e+03 -20.05 < 2e-16 ***
syllable18 -6.17e-02 2.87e-03 4.09e+03 -21.51 < 2e-16 ***
syllable19 -6.62e-02 2.87e-03 4.09e+03 -23.09 < 2e-16 ***
syllable20 -6.46e-02 2.89e-03 4.09e+03 -22.40 < 2e-16 ***
syllable21 -7.15e-02 2.91e-03 4.09e+03 -24.60 < 2e-16 ***
syllable22 -7.16e-02 2.87e-03 4.09e+03 -24.96 < 2e-16 ***
syllable23 -6.70e-02 2.87e-03 4.09e+03 -23.38 < 2e-16 ***
syllable24 -6.90e-02 2.91e-03 4.09e+03 -23.75 < 2e-16 ***
syllable25 -6.11e-02 2.91e-03 4.09e+03 -21.03 < 2e-16 ***
syllable26 -6.38e-02 3.02e-03 4.09e+03 -21.11 < 2e-16 ***
syllable27 -7.23e-02 2.93e-03 4.09e+03 -24.69 < 2e-16 ***
syllable28 -6.93e-02 2.89e-03 4.09e+03 -24.01 < 2e-16 ***
syllable29 -7.25e-02 2.93e-03 4.09e+03 -24.79 < 2e-16 ***
syllable30 -7.29e-02 2.91e-03 4.09e+03 -25.09 < 2e-16 ***
syllable31 -7.29e-02 2.87e-03 4.09e+03 -25.43 < 2e-16 ***
syllable32 -7.27e-02 2.87e-03 4.09e+03 -25.34 < 2e-16 ***
syllable33 -7.19e-02 2.87e-03 4.09e+03 -25.07 < 2e-16 ***
syllable34 -7.61e-02 2.91e-03 4.09e+03 -26.19 < 2e-16 ***
syllable35 -7.56e-02 2.99e-03 4.09e+03 -25.25 < 2e-16 ***
syllable36 -7.61e-02 2.95e-03 4.09e+03 -25.83 < 2e-16 ***
syllable37 -7.75e-02 2.99e-03 4.09e+03 -25.87 < 2e-16 ***
syllable38 -7.20e-02 3.02e-03 4.09e+03 -23.85 < 2e-16 ***
syllable39 -7.71e-02 2.99e-03 4.09e+03 -25.74 < 2e-16 ***
syllable40 -7.78e-02 3.24e-03 4.09e+03 -23.98 < 2e-16 ***
syllable41 -7.53e-02 3.21e-03 4.09e+03 -23.48 < 2e-16 ***
syllable42 -7.75e-02 3.38e-03 4.09e+03 -22.97 < 2e-16 ***
syllable43 -7.73e-02 3.10e-03 4.09e+03 -24.89 < 2e-16 ***
grouppost_w1:syllable1 -2.24e-03 4.06e-03 4.09e+03 -0.55 0.58044
grouppost_w2:syllable1 -3.36e-02 4.65e-03 4.09e+03 -7.24 5.4e-13 ***
grouppost_w1:syllable2 2.70e-02 4.06e-03 4.09e+03 6.66 3.1e-11 ***
grouppost_w2:syllable2 1.38e-02 4.65e-03 4.09e+03 2.96 0.00305 **
grouppost_w1:syllable3 8.12e-03 4.06e-03 4.09e+03 2.00 0.04537 *
grouppost_w2:syllable3 1.47e-02 4.65e-03 4.09e+03 3.16 0.00159 **
grouppost_w1:syllable4 8.62e-03 4.06e-03 4.09e+03 2.13 0.03364 *
grouppost_w2:syllable4 -7.19e-03 4.65e-03 4.09e+03 -1.55 0.12164
grouppost_w1:syllable5 1.99e-02 4.06e-03 4.09e+03 4.90 9.8e-07 ***
grouppost_w2:syllable5 8.64e-03 4.65e-03 4.09e+03 1.86 0.06297 .
grouppost_w1:syllable6 4.05e-02 4.07e-03 4.09e+03 9.95 < 2e-16 ***
grouppost_w2:syllable6 1.08e-02 4.66e-03 4.09e+03 2.33 0.01990 *
grouppost_w1:syllable7 2.28e-02 4.06e-03 4.09e+03 5.63 1.9e-08 ***
grouppost_w2:syllable7 1.05e-02 4.65e-03 4.09e+03 2.26 0.02363 *
grouppost_w1:syllable8 3.25e-02 4.06e-03 4.09e+03 8.02 1.4e-15 ***
grouppost_w2:syllable8 -2.46e-03 4.65e-03 4.09e+03 -0.53 0.59689
grouppost_w1:syllable9 2.20e-02 4.06e-03 4.09e+03 5.42 6.2e-08 ***
grouppost_w2:syllable9 7.85e-03 4.65e-03 4.09e+03 1.69 0.09104 .
grouppost_w1:syllable10 1.38e-02 4.07e-03 4.09e+03 3.38 0.00073 ***
grouppost_w2:syllable10 1.19e-02 4.65e-03 4.09e+03 2.57 0.01019 *
grouppost_w1:syllable11 2.63e-02 4.06e-03 4.09e+03 6.49 9.3e-11 ***
grouppost_w2:syllable11 1.77e-02 4.65e-03 4.09e+03 3.81 0.00014 ***
grouppost_w1:syllable12 2.13e-02 4.06e-03 4.09e+03 5.25 1.6e-07 ***
grouppost_w2:syllable12 1.75e-02 4.65e-03 4.09e+03 3.76 0.00017 ***
grouppost_w1:syllable13 2.24e-02 4.06e-03 4.09e+03 5.53 3.3e-08 ***
grouppost_w2:syllable13 -1.13e-02 4.65e-03 4.09e+03 -2.43 0.01517 *
grouppost_w1:syllable14 2.56e-02 4.06e-03 4.09e+03 6.31 3.2e-10 ***
grouppost_w2:syllable14 5.06e-04 4.65e-03 4.09e+03 0.11 0.91331
grouppost_w1:syllable15 1.98e-02 4.06e-03 4.09e+03 4.88 1.1e-06 ***
grouppost_w2:syllable15 9.54e-03 4.65e-03 4.09e+03 2.05 0.04017 *
grouppost_w1:syllable16 3.16e-02 4.07e-03 4.09e+03 7.77 1.0e-14 ***
grouppost_w2:syllable16 -5.34e-05 4.66e-03 4.09e+03 -0.01 0.99085
grouppost_w1:syllable17 1.78e-02 4.06e-03 4.09e+03 4.39 1.2e-05 ***
grouppost_w2:syllable17 -7.72e-03 4.65e-03 4.09e+03 -1.66 0.09682 .
grouppost_w1:syllable18 1.63e-02 4.06e-03 4.09e+03 4.02 5.9e-05 ***
grouppost_w2:syllable18 5.19e-03 4.65e-03 4.09e+03 1.12 0.26394
grouppost_w1:syllable19 1.81e-02 4.06e-03 4.09e+03 4.47 8.1e-06 ***
grouppost_w2:syllable19 1.55e-02 4.65e-03 4.09e+03 3.33 0.00089 ***
grouppost_w1:syllable20 1.28e-02 4.08e-03 4.09e+03 3.14 0.00171 **
grouppost_w2:syllable20 1.12e-02 4.66e-03 4.09e+03 2.41 0.01582 *
grouppost_w1:syllable21 2.31e-02 4.10e-03 4.09e+03 5.65 1.7e-08 ***
grouppost_w2:syllable21 1.08e-02 4.70e-03 4.09e+03 2.30 0.02152 *
grouppost_w1:syllable22 2.75e-02 4.07e-03 4.09e+03 6.77 1.5e-11 ***
grouppost_w2:syllable22 5.62e-03 4.68e-03 4.09e+03 1.20 0.22968
grouppost_w1:syllable23 1.45e-02 4.08e-03 4.09e+03 3.56 0.00038 ***
grouppost_w2:syllable23 6.07e-03 4.68e-03 4.09e+03 1.30 0.19417
grouppost_w1:syllable24 2.13e-02 4.08e-03 4.09e+03 5.21 2.0e-07 ***
grouppost_w2:syllable24 4.00e-03 4.67e-03 4.09e+03 0.86 0.39132
grouppost_w1:syllable25 9.58e-03 4.08e-03 4.09e+03 2.35 0.01905 *
grouppost_w2:syllable25 -8.30e-03 4.70e-03 4.09e+03 -1.77 0.07752 .
grouppost_w1:syllable26 1.27e-02 4.21e-03 4.09e+03 3.02 0.00256 **
grouppost_w2:syllable26 2.32e-03 4.97e-03 4.09e+03 0.47 0.64034
grouppost_w1:syllable27 2.57e-02 4.10e-03 4.09e+03 6.27 3.9e-10 ***
grouppost_w2:syllable27 5.53e-03 4.82e-03 4.09e+03 1.15 0.25199
grouppost_w1:syllable28 1.51e-02 4.07e-03 4.09e+03 3.70 0.00022 ***
grouppost_w2:syllable28 3.72e-03 4.69e-03 4.09e+03 0.79 0.42710
grouppost_w1:syllable29 2.53e-02 4.17e-03 4.09e+03 6.08 1.3e-09 ***
grouppost_w2:syllable29 8.57e-03 4.91e-03 4.09e+03 1.74 0.08136 .
grouppost_w1:syllable30 2.00e-02 4.08e-03 4.09e+03 4.89 1.1e-06 ***
grouppost_w2:syllable30 8.99e-03 4.67e-03 4.09e+03 1.92 0.05435 .
grouppost_w1:syllable31 2.22e-02 4.06e-03 4.09e+03 5.47 4.7e-08 ***
grouppost_w2:syllable31 4.79e-03 4.65e-03 4.09e+03 1.03 0.30232
grouppost_w1:syllable32 1.96e-02 4.06e-03 4.09e+03 4.82 1.5e-06 ***
grouppost_w2:syllable32 4.52e-03 4.68e-03 4.09e+03 0.97 0.33395
grouppost_w1:syllable33 1.70e-02 4.06e-03 4.09e+03 4.19 2.8e-05 ***
grouppost_w2:syllable33 3.90e-03 4.65e-03 4.09e+03 0.84 0.40067
grouppost_w1:syllable34 2.25e-02 4.16e-03 4.09e+03 5.42 6.3e-08 ***
grouppost_w2:syllable34 4.47e-03 4.85e-03 4.09e+03 0.92 0.35679
grouppost_w1:syllable35 2.44e-02 4.19e-03 4.09e+03 5.82 6.4e-09 ***
grouppost_w2:syllable35 -2.84e-04 5.01e-03 4.09e+03 -0.06 0.95470
grouppost_w1:syllable36 2.09e-02 4.19e-03 4.09e+03 5.00 6.0e-07 ***
grouppost_w2:syllable36 4.47e-03 4.88e-03 4.09e+03 0.92 0.35945
grouppost_w1:syllable37 2.00e-02 4.20e-03 4.09e+03 4.76 2.0e-06 ***
grouppost_w2:syllable37 5.71e-03 4.79e-03 4.09e+03 1.19 0.23293
grouppost_w1:syllable38 1.52e-02 4.35e-03 4.09e+03 3.50 0.00047 ***
grouppost_w2:syllable38 -2.77e-03 5.51e-03 4.09e+03 -0.50 0.61554
grouppost_w1:syllable39 1.90e-02 4.34e-03 4.09e+03 4.37 1.3e-05 ***
grouppost_w2:syllable39 5.15e-03 4.73e-03 4.09e+03 1.09 0.27557
grouppost_w1:syllable40 2.27e-02 4.49e-03 4.09e+03 5.06 4.3e-07 ***
grouppost_w2:syllable40 5.06e-03 4.98e-03 4.09e+03 1.02 0.31004
grouppost_w1:syllable41 1.89e-02 4.42e-03 4.09e+03 4.28 1.9e-05 ***
grouppost_w2:syllable41 7.00e-03 5.33e-03 4.09e+03 1.31 0.18901
grouppost_w1:syllable42 2.21e-02 4.55e-03 4.09e+03 4.85 1.3e-06 ***
grouppost_w2:syllable42 4.88e-03 5.19e-03 4.09e+03 0.94 0.34768
grouppost_w1:syllable43 2.01e-02 4.30e-03 4.09e+03 4.69 2.9e-06 ***
grouppost_w2:syllable43 2.07e-03 4.86e-03 4.09e+03 0.43 0.66942
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 132 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#assumption check 1 - Normality of residuals (should be normally distributed) - passes
qqnorm(resid(model_3ct))
qqline(resid(model_3ct))
#violates
hist(resid(model_3ct))
#Assumption 2 - Homoscedasticity (variance should be consistent) - passes
plot(fitted(model_3ct), resid(model_3ct))
#violates it, not evenly distributed, thus, Heteroscedasticity
#Assumption 3 - confidence intervals - passes
confint(model_3ct, method = "boot")
Computing bootstrap confidence intervals ...
272 message(s): boundary (singular) fit: see help('isSingular')
2.5 % 97.5 %
.sig01 0.000000 0.000706
.sigma 0.012419 0.012940
(Intercept) 0.079681 0.087644
grouppost_w1 -0.026169 -0.014279
grouppost_w2 -0.011065 0.002558
syllable1 -0.000627 0.010600
syllable2 -0.054039 -0.042986
syllable3 -0.049056 -0.037196
syllable4 -0.043206 -0.032172
syllable5 -0.052876 -0.040456
syllable6 -0.060301 -0.049314
syllable7 -0.054684 -0.043033
syllable8 -0.057681 -0.046030
syllable9 -0.056790 -0.045577
syllable10 -0.060908 -0.048022
syllable11 -0.066746 -0.054571
syllable12 -0.064770 -0.053091
syllable13 -0.059334 -0.047613
syllable14 -0.064007 -0.052378
syllable15 -0.065371 -0.054488
syllable16 -0.068369 -0.057074
syllable17 -0.063189 -0.051993
syllable18 -0.067837 -0.055996
syllable19 -0.071623 -0.060022
syllable20 -0.070542 -0.059195
syllable21 -0.076823 -0.065501
syllable22 -0.077211 -0.065934
syllable23 -0.072781 -0.061216
syllable24 -0.074442 -0.063241
syllable25 -0.066800 -0.055926
syllable26 -0.069763 -0.057382
syllable27 -0.078335 -0.065986
syllable28 -0.075078 -0.063626
syllable29 -0.078504 -0.066808
syllable30 -0.079056 -0.066865
syllable31 -0.078821 -0.066929
syllable32 -0.078939 -0.067460
syllable33 -0.077347 -0.066547
syllable34 -0.081613 -0.070519
syllable35 -0.081752 -0.069673
syllable36 -0.081812 -0.070771
syllable37 -0.083501 -0.071823
syllable38 -0.078235 -0.066403
syllable39 -0.083310 -0.070989
syllable40 -0.083730 -0.071089
syllable41 -0.081473 -0.069379
syllable42 -0.083863 -0.071004
syllable43 -0.083161 -0.071370
grouppost_w1:syllable1 -0.010044 0.006673
grouppost_w2:syllable1 -0.043160 -0.024769
grouppost_w1:syllable2 0.019282 0.035326
grouppost_w2:syllable2 0.003849 0.022624
grouppost_w1:syllable3 -0.000529 0.016468
grouppost_w2:syllable3 0.005477 0.024254
grouppost_w1:syllable4 0.000995 0.016793
grouppost_w2:syllable4 -0.017023 0.002604
grouppost_w1:syllable5 0.011752 0.027678
grouppost_w2:syllable5 -0.000984 0.018455
grouppost_w1:syllable6 0.032123 0.048573
grouppost_w2:syllable6 0.001368 0.020648
grouppost_w1:syllable7 0.014296 0.031181
grouppost_w2:syllable7 0.001084 0.019904
grouppost_w1:syllable8 0.024222 0.041146
grouppost_w2:syllable8 -0.011373 0.007841
grouppost_w1:syllable9 0.014299 0.029545
grouppost_w2:syllable9 -0.001522 0.017545
grouppost_w1:syllable10 0.005683 0.022136
grouppost_w2:syllable10 0.002835 0.021198
grouppost_w1:syllable11 0.017744 0.034694
grouppost_w2:syllable11 0.007485 0.027177
grouppost_w1:syllable12 0.012351 0.029792
grouppost_w2:syllable12 0.007738 0.027565
grouppost_w1:syllable13 0.014918 0.031261
grouppost_w2:syllable13 -0.020271 -0.001690
grouppost_w1:syllable14 0.018345 0.033685
grouppost_w2:syllable14 -0.009368 0.009789
grouppost_w1:syllable15 0.011564 0.027842
grouppost_w2:syllable15 0.000225 0.018814
grouppost_w1:syllable16 0.023418 0.039793
grouppost_w2:syllable16 -0.009438 0.008964
grouppost_w1:syllable17 0.010022 0.026031
grouppost_w2:syllable17 -0.016871 0.001172
grouppost_w1:syllable18 0.008593 0.024316
grouppost_w2:syllable18 -0.004640 0.016715
grouppost_w1:syllable19 0.010163 0.026470
grouppost_w2:syllable19 0.006556 0.024782
grouppost_w1:syllable20 0.004460 0.020771
grouppost_w2:syllable20 0.001353 0.021124
grouppost_w1:syllable21 0.014029 0.031569
grouppost_w2:syllable21 0.002094 0.018849
grouppost_w1:syllable22 0.018479 0.035485
grouppost_w2:syllable22 -0.004605 0.015023
grouppost_w1:syllable23 0.006822 0.023086
grouppost_w2:syllable23 -0.003729 0.015586
grouppost_w1:syllable24 0.013625 0.029509
grouppost_w2:syllable24 -0.004321 0.012980
grouppost_w1:syllable25 0.002122 0.017867
grouppost_w2:syllable25 -0.017607 0.001871
grouppost_w1:syllable26 0.003542 0.021359
grouppost_w2:syllable26 -0.006377 0.012547
grouppost_w1:syllable27 0.017339 0.034182
grouppost_w2:syllable27 -0.004380 0.014749
grouppost_w1:syllable28 0.006602 0.023289
grouppost_w2:syllable28 -0.005661 0.013295
grouppost_w1:syllable29 0.017017 0.034186
grouppost_w2:syllable29 -0.001767 0.019734
grouppost_w1:syllable30 0.012267 0.028740
grouppost_w2:syllable30 -0.000157 0.018146
grouppost_w1:syllable31 0.014641 0.029843
grouppost_w2:syllable31 -0.004542 0.015023
grouppost_w1:syllable32 0.011740 0.028083
grouppost_w2:syllable32 -0.005015 0.013657
grouppost_w1:syllable33 0.008535 0.025554
grouppost_w2:syllable33 -0.004936 0.013427
grouppost_w1:syllable34 0.013572 0.030238
grouppost_w2:syllable34 -0.004667 0.013723
grouppost_w1:syllable35 0.015877 0.032872
grouppost_w2:syllable35 -0.010861 0.009801
grouppost_w1:syllable36 0.012138 0.029104
grouppost_w2:syllable36 -0.006211 0.014503
grouppost_w1:syllable37 0.011757 0.029332
grouppost_w2:syllable37 -0.004420 0.016286
grouppost_w1:syllable38 0.007096 0.024589
grouppost_w2:syllable38 -0.013102 0.007139
grouppost_w1:syllable39 0.010484 0.026943
grouppost_w2:syllable39 -0.004070 0.015095
grouppost_w1:syllable40 0.013666 0.031012
grouppost_w2:syllable40 -0.004464 0.014801
grouppost_w1:syllable41 0.011010 0.027560
grouppost_w2:syllable41 -0.004072 0.016674
grouppost_w1:syllable42 0.013777 0.030729
grouppost_w2:syllable42 -0.006161 0.015726
grouppost_w1:syllable43 0.011700 0.029877
grouppost_w2:syllable43 -0.008382 0.011773
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
# Obtain estimated marginal means
emm_3ct <- emmeans(model_3ct, ~ group | syllable) #groupwise effects for each syllable for frequency means
Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
To enable adjustments, add the argument 'pbkrtest.limit = 4219' (or larger)
[or, globally, 'set emm_options(pbkrtest.limit = 4219)' or larger];
but be warned that this may result in large computation time and memory use.
Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
To enable adjustments, add the argument 'lmerTest.limit = 4219' (or larger)
[or, globally, 'set emm_options(lmerTest.limit = 4219)' or larger];
but be warned that this may result in large computation time and memory use.
head(emm_3ct)
group syllable emmean SE df asymp.LCL asymp.UCL
control 0 0.0837 0.00203 Inf 0.0797 0.0876
post_w1 0 0.0637 0.00203 Inf 0.0598 0.0677
post_w2 0 0.0797 0.00258 Inf 0.0746 0.0848
control 1 0.0889 0.00203 Inf 0.0849 0.0929
post_w1 1 0.0667 0.00203 Inf 0.0628 0.0707
post_w2 1 0.0513 0.00258 Inf 0.0462 0.0564
Degrees-of-freedom method: asymptotic
Confidence level used: 0.95
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_3ct <- contrast(emm_3ct, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm
summary(pairwise_3ct)
syllable = 0:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0199 0.00287 Inf 6.950 <.0001
control - post_w2 0.0040 0.00329 Inf 1.210 0.4500
post_w1 - post_w2 -0.0160 0.00329 Inf -4.860 <.0001
syllable = 1:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0222 0.00287 Inf 7.730 <.0001
control - post_w2 0.0376 0.00329 Inf 11.440 <.0001
post_w1 - post_w2 0.0154 0.00329 Inf 4.700 <.0001
syllable = 2:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0071 0.00287 Inf -2.470 0.0360
control - post_w2 -0.0098 0.00329 Inf -2.990 0.0080
post_w1 - post_w2 -0.0027 0.00329 Inf -0.830 0.6830
syllable = 3:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0118 0.00287 Inf 4.120 <.0001
control - post_w2 -0.0107 0.00329 Inf -3.260 0.0030
post_w1 - post_w2 -0.0225 0.00329 Inf -6.860 <.0001
syllable = 4:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0113 0.00287 Inf 3.940 <.0001
control - post_w2 0.0112 0.00329 Inf 3.400 0.0020
post_w1 - post_w2 -0.0001 0.00329 Inf -0.050 0.9990
syllable = 5:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0000 0.00287 Inf 0.010 1.0000
control - post_w2 -0.0047 0.00329 Inf -1.420 0.3280
post_w1 - post_w2 -0.0047 0.00329 Inf -1.440 0.3230
syllable = 6:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0206 0.00289 Inf -7.130 <.0001
control - post_w2 -0.0069 0.00330 Inf -2.090 0.0930
post_w1 - post_w2 0.0137 0.00329 Inf 4.170 <.0001
syllable = 7:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0029 0.00287 Inf -1.010 0.5680
control - post_w2 -0.0066 0.00329 Inf -2.000 0.1130
post_w1 - post_w2 -0.0037 0.00329 Inf -1.110 0.5070
syllable = 8:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0126 0.00287 Inf -4.390 <.0001
control - post_w2 0.0064 0.00329 Inf 1.950 0.1240
post_w1 - post_w2 0.0190 0.00329 Inf 5.790 <.0001
syllable = 9:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0021 0.00287 Inf -0.720 0.7520
control - post_w2 -0.0039 0.00329 Inf -1.180 0.4620
post_w1 - post_w2 -0.0018 0.00329 Inf -0.560 0.8430
syllable = 10:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0062 0.00289 Inf 2.140 0.0820
control - post_w2 -0.0080 0.00329 Inf -2.430 0.0400
post_w1 - post_w2 -0.0142 0.00330 Inf -4.290 <.0001
syllable = 11:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0064 0.00287 Inf -2.240 0.0650
control - post_w2 -0.0138 0.00329 Inf -4.190 <.0001
post_w1 - post_w2 -0.0073 0.00329 Inf -2.230 0.0660
syllable = 12:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0014 0.00287 Inf -0.480 0.8820
control - post_w2 -0.0135 0.00329 Inf -4.110 <.0001
post_w1 - post_w2 -0.0121 0.00329 Inf -3.690 0.0010
syllable = 13:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0025 0.00287 Inf -0.880 0.6530
control - post_w2 0.0152 0.00329 Inf 4.640 <.0001
post_w1 - post_w2 0.0178 0.00329 Inf 5.410 <.0001
syllable = 14:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0056 0.00287 Inf -1.970 0.1200
control - post_w2 0.0035 0.00329 Inf 1.050 0.5440
post_w1 - post_w2 0.0091 0.00329 Inf 2.770 0.0150
syllable = 15:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0001 0.00287 Inf 0.040 0.9990
control - post_w2 -0.0056 0.00329 Inf -1.700 0.2060
post_w1 - post_w2 -0.0057 0.00329 Inf -1.740 0.1920
syllable = 16:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0117 0.00289 Inf -4.040 <.0001
control - post_w2 0.0040 0.00330 Inf 1.220 0.4440
post_w1 - post_w2 0.0157 0.00329 Inf 4.780 <.0001
syllable = 17:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0021 0.00287 Inf 0.740 0.7420
control - post_w2 0.0117 0.00329 Inf 3.550 0.0010
post_w1 - post_w2 0.0096 0.00329 Inf 2.910 0.0100
syllable = 18:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0036 0.00287 Inf 1.260 0.4170
control - post_w2 -0.0012 0.00329 Inf -0.370 0.9260
post_w1 - post_w2 -0.0048 0.00329 Inf -1.480 0.3030
syllable = 19:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0018 0.00287 Inf 0.630 0.8040
control - post_w2 -0.0115 0.00329 Inf -3.500 0.0010
post_w1 - post_w2 -0.0133 0.00329 Inf -4.050 <.0001
syllable = 20:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0071 0.00290 Inf 2.450 0.0380
control - post_w2 -0.0073 0.00330 Inf -2.210 0.0700
post_w1 - post_w2 -0.0144 0.00330 Inf -4.360 <.0001
syllable = 21:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0032 0.00292 Inf -1.100 0.5160
control - post_w2 -0.0068 0.00336 Inf -2.040 0.1030
post_w1 - post_w2 -0.0036 0.00335 Inf -1.090 0.5220
syllable = 22:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0076 0.00289 Inf -2.640 0.0230
control - post_w2 -0.0017 0.00333 Inf -0.500 0.8720
post_w1 - post_w2 0.0060 0.00335 Inf 1.780 0.1760
syllable = 23:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0054 0.00291 Inf 1.860 0.1510
control - post_w2 -0.0021 0.00333 Inf -0.630 0.8010
post_w1 - post_w2 -0.0075 0.00336 Inf -2.230 0.0650
syllable = 24:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0013 0.00291 Inf -0.460 0.8910
control - post_w2 0.0000 0.00332 Inf -0.010 1.0000
post_w1 - post_w2 0.0013 0.00329 Inf 0.390 0.9190
syllable = 25:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0103 0.00291 Inf 3.560 0.0010
control - post_w2 0.0123 0.00336 Inf 3.650 0.0010
post_w1 - post_w2 0.0019 0.00333 Inf 0.580 0.8330
syllable = 26:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0072 0.00308 Inf 2.350 0.0490
control - post_w2 0.0016 0.00373 Inf 0.440 0.8990
post_w1 - post_w2 -0.0056 0.00366 Inf -1.530 0.2770
syllable = 27:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0058 0.00293 Inf -1.980 0.1180
control - post_w2 -0.0016 0.00353 Inf -0.440 0.8970
post_w1 - post_w2 0.0042 0.00348 Inf 1.210 0.4460
syllable = 28:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0049 0.00289 Inf 1.680 0.2120
control - post_w2 0.0002 0.00335 Inf 0.070 0.9970
post_w1 - post_w2 -0.0046 0.00333 Inf -1.390 0.3480
syllable = 29:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0054 0.00303 Inf -1.790 0.1730
control - post_w2 -0.0046 0.00366 Inf -1.260 0.4180
post_w1 - post_w2 0.0008 0.00369 Inf 0.220 0.9730
syllable = 30:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0000 0.00291 Inf -0.010 1.0000
control - post_w2 -0.0050 0.00332 Inf -1.510 0.2840
post_w1 - post_w2 -0.0050 0.00329 Inf -1.520 0.2820
syllable = 31:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0023 0.00287 Inf -0.790 0.7070
control - post_w2 -0.0008 0.00329 Inf -0.250 0.9650
post_w1 - post_w2 0.0014 0.00329 Inf 0.440 0.8990
syllable = 32:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0004 0.00287 Inf 0.130 0.9910
control - post_w2 -0.0006 0.00333 Inf -0.170 0.9850
post_w1 - post_w2 -0.0009 0.00333 Inf -0.280 0.9590
syllable = 33:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0029 0.00287 Inf 1.020 0.5650
control - post_w2 0.0001 0.00329 Inf 0.020 1.0000
post_w1 - post_w2 -0.0029 0.00329 Inf -0.870 0.6580
syllable = 34:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0026 0.00301 Inf -0.870 0.6620
control - post_w2 -0.0005 0.00357 Inf -0.140 0.9890
post_w1 - post_w2 0.0021 0.00363 Inf 0.580 0.8330
syllable = 35:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0044 0.00305 Inf -1.450 0.3130
control - post_w2 0.0042 0.00378 Inf 1.120 0.5000
post_w1 - post_w2 0.0087 0.00373 Inf 2.330 0.0520
syllable = 36:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0010 0.00305 Inf -0.330 0.9420
control - post_w2 -0.0005 0.00361 Inf -0.140 0.9890
post_w1 - post_w2 0.0005 0.00363 Inf 0.140 0.9900
syllable = 37:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0001 0.00307 Inf -0.030 0.9990
control - post_w2 -0.0018 0.00349 Inf -0.500 0.8700
post_w1 - post_w2 -0.0017 0.00345 Inf -0.480 0.8800
syllable = 38:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0047 0.00328 Inf 1.430 0.3260
control - post_w2 0.0067 0.00443 Inf 1.520 0.2810
post_w1 - post_w2 0.0020 0.00451 Inf 0.450 0.8920
syllable = 39:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0010 0.00325 Inf 0.300 0.9520
control - post_w2 -0.0012 0.00340 Inf -0.350 0.9340
post_w1 - post_w2 -0.0022 0.00352 Inf -0.610 0.8130
syllable = 40:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0028 0.00346 Inf -0.810 0.6940
control - post_w2 -0.0011 0.00375 Inf -0.290 0.9540
post_w1 - post_w2 0.0017 0.00363 Inf 0.470 0.8840
syllable = 41:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0010 0.00337 Inf 0.290 0.9540
control - post_w2 -0.0030 0.00420 Inf -0.720 0.7490
post_w1 - post_w2 -0.0040 0.00408 Inf -0.990 0.5860
syllable = 42:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0021 0.00353 Inf -0.610 0.8160
control - post_w2 -0.0009 0.00402 Inf -0.230 0.9720
post_w1 - post_w2 0.0012 0.00375 Inf 0.330 0.9430
syllable = 43:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0002 0.00320 Inf -0.070 0.9970
control - post_w2 0.0019 0.00358 Inf 0.530 0.8580
post_w1 - post_w2 0.0021 0.00346 Inf 0.610 0.8160
Degrees-of-freedom method: asymptotic
P value adjustment: tukey method for comparing a family of 3 estimates
#this data will be used for plotting
# Convert the pairwise results into a data frame using summary
pairwise_results_3ct <- summary(pairwise_3ct)
# Filter significant results (p-value < 0.05)
sig_results_3ct <- pairwise_results_3ct[pairwise_results_3ct$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_3ct <- sig_results_3ct %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
# Print sig_syllables to check
print(sig_syllables_3ct)
#for ggplot below
syllable_labels_3ct <- c(
"0" = "0 (rear_chamber)",
"1" = "1 (stand_still)",
"2" = "2 (accelerate_short)",
"3" = "3 (accelerate_arch)",
"4" = "4 (rear_supported)",
"5" = "5 (turn_left_sharp)",
"6" = "6 (turn_right_sharp)",
"7" = "7 (sniff_up)",
"8" = "8 (accelerate_chamber)",
"9" = "9 (turn_left_moderate)",
"10" = "10 (turn_right_moderate)",
"11" = "11 (sniff_locomotion)",
"12" = "12 (sniff_arch_before)",
"13" = "13 (sniff_arch_after)",
"14" = "14 (accelerate_medium)",
"15" = "15 (head_retract)",
"16" = "16 (sniff_wall)",
"17" = "17 (rear_supported_sporadic)",
"18" = "18 (thigmotaxis_left)",
"19" = "19 (thigmotaxis_chamber)",
"20" = "20 (thigmotaxsis_divider)",
"21" = "21 (accelerate_arch_right)",
"22" = "22 (head_turn_left)",
"23" = "23 (unknown)",
"24" = "24 (unknown)",
"25" = "25 (standstill_arch)",
"26" = "26 (head_turn_right)",
"27" = "27 (unknown)",
"28" = "28 (sniff_wall)",
"29" = "29 (look)",
"30" = "30 (thigmotaxis_arch)",
"31" = "31 (sniff_stationary)",
"32" = "32 (head_dip_arch)",
"33" = "33 (arch_angle_left)",
"34" = "34 (arch_angle_right)",
"35" = "35 (groom_curled)",
"36" = "36 (unknown)",
"37" = "37 (unknown)",
"38" = "38 (thigmotaxis_right)"
)
# Calculate means by syllable and group
means_3ct <- df_3ct %>%
group_by(syllable, group) %>%
summarize(
mean_freq_3ct = mean(frequency, na.rm = TRUE),
se_3ct = sd(frequency, na.rm = TRUE)/sqrt(n())
)
`summarise()` has grouped output by 'syllable'. You can override using the `.groups` argument.
# Create the plot
plot_3ct <- ggplot(means_3ct, aes(x = syllable, y = mean_freq_3ct, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = mean_freq_3ct - se_3ct, ymax = mean_freq_3ct + se_3ct), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_3ct) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_3ct <- plot_3ct + geom_text(
data = sig_syllables_3ct,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_3ct
#ggsave("3ct_graph.png", plot = plot_3ct, width = 14, height = 6) #makes spaces visible
emm_3ct
syllable = 0:
group emmean SE df asymp.LCL asymp.UCL
control 0.0837 0.00203 Inf 0.0797 0.0876
post_w1 0.0637 0.00203 Inf 0.0598 0.0677
post_w2 0.0797 0.00258 Inf 0.0746 0.0848
syllable = 1:
group emmean SE df asymp.LCL asymp.UCL
control 0.0889 0.00203 Inf 0.0849 0.0929
post_w1 0.0667 0.00203 Inf 0.0628 0.0707
post_w2 0.0513 0.00258 Inf 0.0462 0.0564
syllable = 2:
group emmean SE df asymp.LCL asymp.UCL
control 0.0350 0.00203 Inf 0.0311 0.0390
post_w1 0.0421 0.00203 Inf 0.0381 0.0461
post_w2 0.0448 0.00258 Inf 0.0398 0.0499
syllable = 3:
group emmean SE df asymp.LCL asymp.UCL
control 0.0402 0.00203 Inf 0.0362 0.0441
post_w1 0.0284 0.00203 Inf 0.0244 0.0323
post_w2 0.0509 0.00258 Inf 0.0458 0.0559
syllable = 4:
group emmean SE df asymp.LCL asymp.UCL
control 0.0461 0.00203 Inf 0.0421 0.0501
post_w1 0.0348 0.00203 Inf 0.0308 0.0388
post_w2 0.0349 0.00258 Inf 0.0299 0.0400
syllable = 5:
group emmean SE df asymp.LCL asymp.UCL
control 0.0368 0.00203 Inf 0.0328 0.0407
post_w1 0.0367 0.00203 Inf 0.0327 0.0407
post_w2 0.0414 0.00258 Inf 0.0364 0.0465
syllable = 6:
group emmean SE df asymp.LCL asymp.UCL
control 0.0290 0.00205 Inf 0.0250 0.0330
post_w1 0.0496 0.00203 Inf 0.0456 0.0535
post_w2 0.0359 0.00258 Inf 0.0308 0.0409
syllable = 7:
group emmean SE df asymp.LCL asymp.UCL
control 0.0345 0.00203 Inf 0.0305 0.0384
post_w1 0.0374 0.00203 Inf 0.0334 0.0414
post_w2 0.0410 0.00258 Inf 0.0360 0.0461
syllable = 8:
group emmean SE df asymp.LCL asymp.UCL
control 0.0320 0.00203 Inf 0.0280 0.0360
post_w1 0.0446 0.00203 Inf 0.0406 0.0486
post_w2 0.0256 0.00258 Inf 0.0205 0.0306
syllable = 9:
group emmean SE df asymp.LCL asymp.UCL
control 0.0328 0.00203 Inf 0.0288 0.0368
post_w1 0.0349 0.00203 Inf 0.0309 0.0388
post_w2 0.0367 0.00258 Inf 0.0316 0.0418
syllable = 10:
group emmean SE df asymp.LCL asymp.UCL
control 0.0289 0.00203 Inf 0.0249 0.0329
post_w1 0.0227 0.00205 Inf 0.0187 0.0268
post_w2 0.0369 0.00258 Inf 0.0318 0.0420
syllable = 11:
group emmean SE df asymp.LCL asymp.UCL
control 0.0227 0.00203 Inf 0.0188 0.0267
post_w1 0.0291 0.00203 Inf 0.0252 0.0331
post_w2 0.0365 0.00258 Inf 0.0314 0.0415
syllable = 12:
group emmean SE df asymp.LCL asymp.UCL
control 0.0245 0.00203 Inf 0.0205 0.0285
post_w1 0.0259 0.00203 Inf 0.0219 0.0299
post_w2 0.0380 0.00258 Inf 0.0330 0.0431
syllable = 13:
group emmean SE df asymp.LCL asymp.UCL
control 0.0307 0.00203 Inf 0.0268 0.0347
post_w1 0.0333 0.00203 Inf 0.0293 0.0372
post_w2 0.0155 0.00258 Inf 0.0104 0.0206
syllable = 14:
group emmean SE df asymp.LCL asymp.UCL
control 0.0255 0.00203 Inf 0.0215 0.0294
post_w1 0.0311 0.00203 Inf 0.0271 0.0351
post_w2 0.0220 0.00258 Inf 0.0170 0.0271
syllable = 15:
group emmean SE df asymp.LCL asymp.UCL
control 0.0237 0.00203 Inf 0.0197 0.0276
post_w1 0.0235 0.00203 Inf 0.0196 0.0275
post_w2 0.0292 0.00258 Inf 0.0242 0.0343
syllable = 16:
group emmean SE df asymp.LCL asymp.UCL
control 0.0208 0.00205 Inf 0.0168 0.0248
post_w1 0.0325 0.00203 Inf 0.0285 0.0365
post_w2 0.0168 0.00258 Inf 0.0117 0.0219
syllable = 17:
group emmean SE df asymp.LCL asymp.UCL
control 0.0262 0.00203 Inf 0.0222 0.0301
post_w1 0.0241 0.00203 Inf 0.0201 0.0280
post_w2 0.0145 0.00258 Inf 0.0094 0.0196
syllable = 18:
group emmean SE df asymp.LCL asymp.UCL
control 0.0220 0.00203 Inf 0.0180 0.0260
post_w1 0.0184 0.00203 Inf 0.0144 0.0223
post_w2 0.0232 0.00258 Inf 0.0181 0.0283
syllable = 19:
group emmean SE df asymp.LCL asymp.UCL
control 0.0175 0.00203 Inf 0.0135 0.0214
post_w1 0.0156 0.00203 Inf 0.0117 0.0196
post_w2 0.0289 0.00258 Inf 0.0239 0.0340
syllable = 20:
group emmean SE df asymp.LCL asymp.UCL
control 0.0190 0.00205 Inf 0.0150 0.0230
post_w1 0.0119 0.00205 Inf 0.0079 0.0159
post_w2 0.0263 0.00258 Inf 0.0212 0.0314
syllable = 21:
group emmean SE df asymp.LCL asymp.UCL
control 0.0122 0.00208 Inf 0.0081 0.0163
post_w1 0.0154 0.00205 Inf 0.0114 0.0194
post_w2 0.0190 0.00264 Inf 0.0139 0.0242
syllable = 22:
group emmean SE df asymp.LCL asymp.UCL
control 0.0121 0.00203 Inf 0.0081 0.0160
post_w1 0.0197 0.00205 Inf 0.0157 0.0237
post_w2 0.0137 0.00264 Inf 0.0086 0.0189
syllable = 23:
group emmean SE df asymp.LCL asymp.UCL
control 0.0166 0.00203 Inf 0.0126 0.0206
post_w1 0.0112 0.00208 Inf 0.0071 0.0153
post_w2 0.0187 0.00264 Inf 0.0136 0.0239
syllable = 24:
group emmean SE df asymp.LCL asymp.UCL
control 0.0146 0.00208 Inf 0.0106 0.0187
post_w1 0.0160 0.00203 Inf 0.0120 0.0199
post_w2 0.0147 0.00258 Inf 0.0096 0.0198
syllable = 25:
group emmean SE df asymp.LCL asymp.UCL
control 0.0225 0.00208 Inf 0.0185 0.0266
post_w1 0.0122 0.00203 Inf 0.0082 0.0162
post_w2 0.0103 0.00264 Inf 0.0051 0.0155
syllable = 26:
group emmean SE df asymp.LCL asymp.UCL
control 0.0199 0.00224 Inf 0.0155 0.0243
post_w1 0.0127 0.00211 Inf 0.0085 0.0168
post_w2 0.0183 0.00298 Inf 0.0124 0.0241
syllable = 27:
group emmean SE df asymp.LCL asymp.UCL
control 0.0114 0.00211 Inf 0.0073 0.0155
post_w1 0.0172 0.00203 Inf 0.0132 0.0212
post_w2 0.0130 0.00283 Inf 0.0074 0.0185
syllable = 28:
group emmean SE df asymp.LCL asymp.UCL
control 0.0143 0.00205 Inf 0.0103 0.0184
post_w1 0.0095 0.00203 Inf 0.0055 0.0135
post_w2 0.0141 0.00264 Inf 0.0089 0.0193
syllable = 29:
group emmean SE df asymp.LCL asymp.UCL
control 0.0111 0.00211 Inf 0.0070 0.0152
post_w1 0.0165 0.00217 Inf 0.0123 0.0208
post_w2 0.0157 0.00298 Inf 0.0099 0.0216
syllable = 30:
group emmean SE df asymp.LCL asymp.UCL
control 0.0107 0.00208 Inf 0.0067 0.0148
post_w1 0.0108 0.00203 Inf 0.0068 0.0148
post_w2 0.0158 0.00258 Inf 0.0107 0.0208
syllable = 31:
group emmean SE df asymp.LCL asymp.UCL
control 0.0107 0.00203 Inf 0.0068 0.0147
post_w1 0.0130 0.00203 Inf 0.0090 0.0170
post_w2 0.0116 0.00258 Inf 0.0065 0.0166
syllable = 32:
group emmean SE df asymp.LCL asymp.UCL
control 0.0110 0.00203 Inf 0.0070 0.0150
post_w1 0.0106 0.00203 Inf 0.0067 0.0146
post_w2 0.0116 0.00264 Inf 0.0064 0.0167
syllable = 33:
group emmean SE df asymp.LCL asymp.UCL
control 0.0118 0.00203 Inf 0.0078 0.0157
post_w1 0.0088 0.00203 Inf 0.0049 0.0128
post_w2 0.0117 0.00258 Inf 0.0066 0.0168
syllable = 34:
group emmean SE df asymp.LCL asymp.UCL
control 0.0075 0.00208 Inf 0.0035 0.0116
post_w1 0.0101 0.00217 Inf 0.0059 0.0144
post_w2 0.0080 0.00290 Inf 0.0024 0.0137
syllable = 35:
group emmean SE df asymp.LCL asymp.UCL
control 0.0080 0.00220 Inf 0.0037 0.0124
post_w1 0.0125 0.00211 Inf 0.0083 0.0166
post_w2 0.0038 0.00307 Inf -0.0022 0.0098
syllable = 36:
group emmean SE df asymp.LCL asymp.UCL
control 0.0075 0.00214 Inf 0.0033 0.0117
post_w1 0.0085 0.00217 Inf 0.0043 0.0128
post_w2 0.0080 0.00290 Inf 0.0023 0.0137
syllable = 37:
group emmean SE df asymp.LCL asymp.UCL
control 0.0062 0.00220 Inf 0.0018 0.0105
post_w1 0.0063 0.00214 Inf 0.0021 0.0105
post_w2 0.0079 0.00270 Inf 0.0026 0.0132
syllable = 38:
group emmean SE df asymp.LCL asymp.UCL
control 0.0116 0.00224 Inf 0.0072 0.0160
post_w1 0.0069 0.00239 Inf 0.0023 0.0116
post_w2 0.0049 0.00382 Inf -0.0026 0.0124
syllable = 39:
group emmean SE df asymp.LCL asymp.UCL
control 0.0066 0.00220 Inf 0.0022 0.0109
post_w1 0.0056 0.00239 Inf 0.0009 0.0103
post_w2 0.0077 0.00258 Inf 0.0027 0.0128
syllable = 40:
group emmean SE df asymp.LCL asymp.UCL
control 0.0059 0.00253 Inf 0.0009 0.0108
post_w1 0.0087 0.00235 Inf 0.0041 0.0133
post_w2 0.0070 0.00276 Inf 0.0016 0.0124
syllable = 41:
group emmean SE df asymp.LCL asymp.UCL
control 0.0084 0.00248 Inf 0.0035 0.0132
post_w1 0.0074 0.00227 Inf 0.0029 0.0119
post_w2 0.0114 0.00338 Inf 0.0048 0.0180
syllable = 42:
group emmean SE df asymp.LCL asymp.UCL
control 0.0061 0.00270 Inf 0.0008 0.0114
post_w1 0.0083 0.00227 Inf 0.0038 0.0127
post_w2 0.0070 0.00298 Inf 0.0012 0.0129
syllable = 43:
group emmean SE df asymp.LCL asymp.UCL
control 0.0064 0.00235 Inf 0.0018 0.0110
post_w1 0.0066 0.00217 Inf 0.0023 0.0109
post_w2 0.0045 0.00270 Inf -0.0008 0.0098
Degrees-of-freedom method: asymptotic
Confidence level used: 0.95
# extract results from the emm_3ct
emm_df_3ct <- as.data.frame(emm_3ct) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, asymp.LCL, asymp.UCL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
head(emm_df_3ct)
# Create the plot
plot_3ct <- ggplot(emm_df_3ct, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_3ct) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_3ct <- plot_3ct + geom_text(
data = sig_syllables_3ct,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_3ct
#ggsave("3ct_graph(SE).png", plot = plot_3ct, width = 14, height = 6) #makes spaces visible
#nor_SE_model
# extract results from the emm_3ct
emm_df_nor <- as.data.frame(emm_nor) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
head(emm_df_nor)
# Create the plot
plot_nor <- ggplot(emm_df_nor, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_nor) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_nor <- plot_nor + geom_text(
data = sig_syllables_nor,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_nor
#ggsave("nor_graph(SE).png", plot = plot_nor, width = 10, height = 6) #makes spaces visible
#oft_SE_model
# extract results from the emm_3ct
emm_df_oft <- as.data.frame(emm_oft) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_oft
# Create the plot
plot_oft <- ggplot(emm_df_oft, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_oft <- plot_oft + geom_text(
data = sig_syllables_oft,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_oft
#ggsave("oft_graph(SE).png", plot = plot_oft, width = 10, height = 6) #makes spaces visible
# extract results from the emm_3ct
emm_df_oft <- as.data.frame(emm_oft) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_oft
# Get syllables in descending order of emmean from the control group
syllable_order <- emm_df_oft %>%
filter(group == "control") %>%
arrange(desc(emmean)) %>% #computed mean frequency sorted from most to least
pull(syllable) %>% # Extract just the ordered syllable names, this controls x-axis of plot
as.character()
# Reapply the factor with new levels
emm_df_oft <- emm_df_oft %>%
mutate(syllable = factor(syllable, levels = syllable_order))
emm_df_oft
#this data will be used for plotting
# Apply the same syllable ordering as in emm_df_oft
# Convert the pairwise results into a data frame using summary
pairwise_results_oft <- summary(pairwise_oft)
# Filter significant results (p-value < 0.05)
sig_results_oft <- pairwise_results_oft[pairwise_results_oft$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_oft <- sig_results_oft %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
sig_syllables_oft <- sig_syllables_oft %>%
mutate(syllable = factor(syllable, levels = levels(emm_df_oft$syllable)))
# Print sig_syllables to check
print(sig_syllables_oft)
#check if factor ordering is same
levels(emm_df_oft$syllable)
[1] "0" "1" "2" "3" "4" "5" "9" "11" "7" "8" "20" "21" "6" "13" "14" "16" "18" "12" "22" "23" "17"
[22] "28" "15" "24" "25" "26" "10" "27" "19"
levels(sig_syllables_oft$syllable)
[1] "0" "1" "2" "3" "4" "5" "9" "11" "7" "8" "20" "21" "6" "13" "14" "16" "18" "12" "22" "23" "17"
[22] "28" "15" "24" "25" "26" "10" "27" "19"
# Create the plot
plot_oft <- ggplot(emm_df_oft, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft) +
# Labels for axes and legend
labs(
x = "Syllables (Order by Control Frequency)",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_oft <- plot_oft + geom_text(
data = sig_syllables_oft,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_oft
#ggsave("oft_graph(SE_order).png", plot = plot_oft, width = 10, height = 6) #makes spaces visible
#epm_SE_model
# extract results from the emm_3ct
emm_df_epm <- as.data.frame(emm_epm) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_epm
# Create the plot
plot_epm <- ggplot(emm_df_epm, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_epm) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_epm <- plot_epm + geom_text(
data = sig_syllables_epm,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "control - post_w2" ~ 0.24,
contrast == "post_w1 - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_epm
ggsave("epm_graph(SE).png", plot = plot_epm, width = 10, height = 6) #makes spaces visible
#OFT_ordered_SE
#load results file and make sure headings and levels are established
df_oft <- read.csv("NEW_new_moseq_OFT_stats.csv", header=TRUE)
df_oft$syllable <- factor(df_oft$syllable) # Convert to categorical
df_oft$group <- factor(df_oft$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
#cool fact, code above sets "control" as baseline value as it comes first
df_oft$ID <- factor(df_oft$ID)
str(df_oft)
'data.frame': 977 obs. of 18 variables:
$ group : Factor w/ 3 levels "control","post_w1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ name : chr "pre-induction_OFT_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-fasterrcnn_mobilenet_v3_large_fpn-004_"| __truncated__ "pre-induction_OFT_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-fasterrcnn_mobilenet_v3_large_fpn-004_"| __truncated__ "pre-induction_OFT_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-fasterrcnn_mobilenet_v3_large_fpn-004_"| __truncated__ "pre-induction_OFT_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-fasterrcnn_mobilenet_v3_large_fpn-004_"| __truncated__ ...
$ ID : Factor w/ 13 levels "98","102","112",..: 7 7 7 7 7 7 7 7 7 7 ...
$ syllable : Factor w/ 29 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
$ heading_mean : num 0.2216 -0.364 -0.4371 -0.0628 -0.6118 ...
$ heading_std : num 1.73 1.77 1.78 1.61 1.61 ...
$ heading_min : num -3.14 -3.13 -3.14 -3.14 -3.14 ...
$ heading_max : num 3.14 3.13 3.14 3.11 3.12 ...
$ angular_velocity_mean: num 0.4746 -0.2841 -0.1903 0.8449 0.0634 ...
$ angular_velocity_std : num 14.7 14.4 15 15.6 21.2 ...
$ angular_velocity_min : num -313.52 -312.52 -314.09 -310.76 -8.32 ...
$ angular_velocity_max : num 313.92 312.95 314.03 7.28 313.64 ...
$ velocity_px_s_mean : num 89 77.3 39.7 160.6 188.1 ...
$ velocity_px_s_std : num 96.9 58.2 41.2 120.2 126.5 ...
$ velocity_px_s_min : num 0.81 1.569 0.671 0.587 5.501 ...
$ velocity_px_s_max : num 561 481 447 624 593 ...
$ frequency : num 0.1554 0.14 0.0985 0.0853 0.0613 ...
$ duration : num 1.286 1.175 0.97 0.819 0.779 ...
model_oft <- lmer(frequency ~ group * syllable + (1 | ID), data = df_oft)
boundary (singular) fit: see help('isSingular')
summary(model_oft)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_oft
REML criterion at convergence: -4232
Scaled residuals:
Min 1Q Median 3Q Max
-4.655 -0.441 -0.096 0.347 5.477
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.000000 0.00
Residual 0.000399 0.02
Number of obs: 977, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 0.15601 0.00554 890.00000 28.17 < 2e-16 ***
grouppost_w1 0.02151 0.00783 890.00000 2.75 0.00614 **
grouppost_w2 -0.01872 0.00818 890.00000 -2.29 0.02232 *
syllable1 -0.01760 0.00783 890.00000 -2.25 0.02486 *
syllable2 -0.05535 0.00783 890.00000 -7.07 3.2e-12 ***
syllable3 -0.09083 0.00783 890.00000 -11.60 < 2e-16 ***
syllable4 -0.10562 0.00783 890.00000 -13.49 < 2e-16 ***
syllable5 -0.10864 0.00783 890.00000 -13.87 < 2e-16 ***
syllable6 -0.13416 0.00783 890.00000 -17.13 < 2e-16 ***
syllable7 -0.11440 0.00783 890.00000 -14.61 < 2e-16 ***
syllable8 -0.12602 0.00783 890.00000 -16.09 < 2e-16 ***
syllable9 -0.10969 0.00783 890.00000 -14.01 < 2e-16 ***
syllable10 -0.14808 0.00799 890.00000 -18.53 < 2e-16 ***
syllable11 -0.11148 0.00783 890.00000 -14.23 < 2e-16 ***
syllable12 -0.14082 0.00799 890.00000 -17.62 < 2e-16 ***
syllable13 -0.13796 0.00783 890.00000 -17.61 < 2e-16 ***
syllable14 -0.13986 0.00783 890.00000 -17.86 < 2e-16 ***
syllable15 -0.14695 0.00818 890.00000 -17.96 < 2e-16 ***
syllable16 -0.14019 0.00783 890.00000 -17.90 < 2e-16 ***
syllable17 -0.14585 0.00799 890.00000 -18.25 < 2e-16 ***
syllable18 -0.14082 0.00840 890.00000 -16.77 < 2e-16 ***
syllable19 -0.15080 0.00866 890.00000 -17.42 < 2e-16 ***
syllable20 -0.13212 0.00799 890.00000 -16.53 < 2e-16 ***
syllable21 -0.13229 0.00783 890.00000 -16.89 < 2e-16 ***
syllable22 -0.14132 0.00799 890.00000 -17.68 < 2e-16 ***
syllable23 -0.14310 0.00818 890.00000 -17.49 < 2e-16 ***
syllable24 -0.14771 0.00799 890.00000 -18.48 < 2e-16 ***
syllable25 -0.14795 0.00799 890.00000 -18.51 < 2e-16 ***
syllable26 -0.14799 0.00818 890.00000 -18.09 < 2e-16 ***
syllable27 -0.15026 0.00936 890.00000 -16.05 < 2e-16 ***
syllable28 -0.14648 0.00840 890.00000 -17.44 < 2e-16 ***
grouppost_w1:syllable1 -0.01095 0.01108 890.00000 -0.99 0.32319
grouppost_w2:syllable1 0.02279 0.01157 890.00000 1.97 0.04916 *
grouppost_w1:syllable2 -0.03385 0.01108 890.00000 -3.06 0.00231 **
grouppost_w2:syllable2 -0.03127 0.01157 890.00000 -2.70 0.00700 **
grouppost_w1:syllable3 -0.01601 0.01108 890.00000 -1.45 0.14879
grouppost_w2:syllable3 0.05035 0.01157 890.00000 4.35 1.5e-05 ***
grouppost_w1:syllable4 -0.00879 0.01108 890.00000 -0.79 0.42775
grouppost_w2:syllable4 0.06689 0.01157 890.00000 5.78 1.0e-08 ***
grouppost_w1:syllable5 -0.03146 0.01108 890.00000 -2.84 0.00461 **
grouppost_w2:syllable5 0.01689 0.01157 890.00000 1.46 0.14476
grouppost_w1:syllable6 -0.01673 0.01108 890.00000 -1.51 0.13130
grouppost_w2:syllable6 0.04199 0.01157 890.00000 3.63 0.00030 ***
grouppost_w1:syllable7 -0.03748 0.01108 890.00000 -3.38 0.00075 ***
grouppost_w2:syllable7 0.00526 0.01157 890.00000 0.45 0.64973
grouppost_w1:syllable8 -0.01837 0.01108 890.00000 -1.66 0.09754 .
grouppost_w2:syllable8 0.01160 0.01157 890.00000 1.00 0.31648
grouppost_w1:syllable9 -0.04496 0.01108 890.00000 -4.06 5.4e-05 ***
grouppost_w2:syllable9 -0.01053 0.01157 890.00000 -0.91 0.36276
grouppost_w1:syllable10 -0.01142 0.01119 890.00000 -1.02 0.30778
grouppost_w2:syllable10 0.06632 0.01168 890.00000 5.68 1.8e-08 ***
grouppost_w1:syllable11 -0.04738 0.01133 890.00000 -4.18 3.1e-05 ***
grouppost_w2:syllable11 -0.01525 0.01172 890.00000 -1.30 0.19368
grouppost_w1:syllable12 -0.01107 0.01130 890.00000 -0.98 0.32771
grouppost_w2:syllable12 0.02634 0.01168 890.00000 2.26 0.02433 *
grouppost_w1:syllable13 -0.02410 0.01108 890.00000 -2.18 0.02984 *
grouppost_w2:syllable13 0.02867 0.01157 890.00000 2.48 0.01339 *
grouppost_w1:syllable14 -0.01576 0.01108 890.00000 -1.42 0.15521
grouppost_w2:syllable14 0.02605 0.01157 890.00000 2.25 0.02458 *
grouppost_w1:syllable15 -0.01682 0.01144 890.00000 -1.47 0.14168
grouppost_w2:syllable15 0.03755 0.01181 890.00000 3.18 0.00152 **
grouppost_w1:syllable16 -0.01958 0.01108 890.00000 -1.77 0.07742 .
grouppost_w2:syllable16 0.01452 0.01157 890.00000 1.26 0.20978
grouppost_w1:syllable17 -0.01007 0.01159 890.00000 -0.87 0.38519
grouppost_w2:syllable17 0.02553 0.01202 890.00000 2.12 0.03395 *
grouppost_w1:syllable18 -0.02146 0.01172 890.00000 -1.83 0.06750 .
grouppost_w2:syllable18 0.01961 0.01229 890.00000 1.60 0.11103
grouppost_w1:syllable19 -0.01162 0.01191 890.00000 -0.98 0.32968
grouppost_w2:syllable19 0.04048 0.01229 890.00000 3.29 0.00103 **
grouppost_w1:syllable20 -0.03668 0.01130 890.00000 -3.24 0.00122 **
grouppost_w2:syllable20 0.00171 0.01225 890.00000 0.14 0.88927
grouppost_w1:syllable21 -0.03774 0.01119 890.00000 -3.37 0.00078 ***
grouppost_w2:syllable21 0.00214 0.01405 890.00000 0.15 0.87901
grouppost_w1:syllable22 -0.02178 0.01119 890.00000 -1.95 0.05190 .
grouppost_w2:syllable22 0.00984 0.01202 890.00000 0.82 0.41308
grouppost_w1:syllable23 -0.01973 0.01157 890.00000 -1.71 0.08852 .
grouppost_w2:syllable23 0.01328 0.01237 890.00000 1.07 0.28331
grouppost_w1:syllable24 -0.01789 0.01159 890.00000 -1.54 0.12327
grouppost_w2:syllable24 0.01697 0.01291 890.00000 1.32 0.18884
grouppost_w1:syllable25 -0.02144 0.01144 890.00000 -1.87 0.06122 .
grouppost_w2:syllable25 0.01666 0.01183 890.00000 1.41 0.15939
grouppost_w1:syllable26 -0.02032 0.01144 890.00000 -1.78 0.07590 .
grouppost_w2:syllable26 0.01483 0.01237 890.00000 1.20 0.23088
grouppost_w1:syllable27 -0.01409 0.01297 890.00000 -1.09 0.27752
grouppost_w2:syllable27 0.02020 0.01345 890.00000 1.50 0.13350
grouppost_w1:syllable28 -0.02423 0.01188 890.00000 -2.04 0.04162 *
grouppost_w2:syllable28 0.01317 0.01280 890.00000 1.03 0.30372
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 87 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
# Get the AIC values for each model, lower AIC = better
#AIC(model_1_syllable, model_name)
#anova(model_name,model_simple) #thus, use model_name
#assumption check 1 - Normality of residuals (should be normally distributed) - passes
qqnorm(resid(model_oft))
qqline(resid(model_oft))
#probs a lil' bit non-normal, thus, whe calculating confidence intervals, used "boot" method which assumes non-normality
#Assumption 2 - Homoscedasticity (variance should be consistent) - passes
plot(fitted(model_oft), resid(model_oft))
#violates it, not evenly distributed, thus, Heteroscedasticity
effect_oft = eta_squared(model_oft)
print(effect_oft)
# Effect Size for ANOVA (Type III)
Parameter | Eta2 (partial) | 95% CI
----------------------------------------------
group | 7.47e-05 | [0.00, 1.00]
syllable | 0.80 | [0.78, 1.00]
group:syllable | 0.21 | [0.13, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
#0 to 1, 1 being factor has huge effect on the frequency
#Assumption 3 - confidence intervals - passes
confint(model_oft, method = "boot")
Computing bootstrap confidence intervals ...
292 message(s): boundary (singular) fit: see help('isSingular')
2.5 % 97.5 %
.sig01 0.000000 0.00223
.sigma 0.018999 0.02084
(Intercept) 0.145408 0.16626
grouppost_w1 0.006941 0.03650
grouppost_w2 -0.034140 -0.00255
syllable1 -0.030774 -0.00222
syllable2 -0.070512 -0.03986
syllable3 -0.105241 -0.07545
syllable4 -0.121585 -0.09099
syllable5 -0.122156 -0.09339
syllable6 -0.150926 -0.11771
syllable7 -0.128747 -0.09927
syllable8 -0.141075 -0.10975
syllable9 -0.124513 -0.09453
syllable10 -0.162322 -0.13194
syllable11 -0.125061 -0.09608
syllable12 -0.155829 -0.12411
syllable13 -0.153095 -0.12270
syllable14 -0.155180 -0.12495
syllable15 -0.163210 -0.13198
syllable16 -0.155028 -0.12480
syllable17 -0.160413 -0.12990
syllable18 -0.157858 -0.12545
syllable19 -0.167559 -0.13479
syllable20 -0.148008 -0.11599
syllable21 -0.146435 -0.11774
syllable22 -0.155217 -0.12598
syllable23 -0.158002 -0.12790
syllable24 -0.162578 -0.13310
syllable25 -0.163888 -0.13169
syllable26 -0.163916 -0.13184
syllable27 -0.168449 -0.13075
syllable28 -0.163229 -0.12939
grouppost_w1:syllable1 -0.032730 0.00947
grouppost_w2:syllable1 0.000297 0.04801
grouppost_w1:syllable2 -0.054664 -0.01141
grouppost_w2:syllable2 -0.054676 -0.00885
grouppost_w1:syllable3 -0.037546 0.00659
grouppost_w2:syllable3 0.026594 0.07055
grouppost_w1:syllable4 -0.030449 0.01439
grouppost_w2:syllable4 0.044087 0.09366
grouppost_w1:syllable5 -0.055944 -0.01044
grouppost_w2:syllable5 -0.005166 0.04112
grouppost_w1:syllable6 -0.039864 0.00336
grouppost_w2:syllable6 0.019862 0.06561
grouppost_w1:syllable7 -0.058509 -0.01687
grouppost_w2:syllable7 -0.020369 0.02920
grouppost_w1:syllable8 -0.038873 0.00419
grouppost_w2:syllable8 -0.011992 0.03457
grouppost_w1:syllable9 -0.065102 -0.02585
grouppost_w2:syllable9 -0.031545 0.01192
grouppost_w1:syllable10 -0.032262 0.00740
grouppost_w2:syllable10 0.041815 0.08726
grouppost_w1:syllable11 -0.069135 -0.02772
grouppost_w2:syllable11 -0.038711 0.00849
grouppost_w1:syllable12 -0.034013 0.01037
grouppost_w2:syllable12 0.003427 0.04794
grouppost_w1:syllable13 -0.047481 -0.00174
grouppost_w2:syllable13 0.003285 0.05137
grouppost_w1:syllable14 -0.038929 0.00612
grouppost_w2:syllable14 0.002618 0.04895
grouppost_w1:syllable15 -0.038792 0.00526
grouppost_w2:syllable15 0.014709 0.06059
grouppost_w1:syllable16 -0.042684 0.00126
grouppost_w2:syllable16 -0.009894 0.03787
grouppost_w1:syllable17 -0.033622 0.01117
grouppost_w2:syllable17 0.002279 0.04766
grouppost_w1:syllable18 -0.042409 0.00311
grouppost_w2:syllable18 -0.006524 0.04321
grouppost_w1:syllable19 -0.036507 0.01375
grouppost_w2:syllable19 0.015887 0.06621
grouppost_w1:syllable20 -0.059259 -0.01476
grouppost_w2:syllable20 -0.022201 0.02605
grouppost_w1:syllable21 -0.059106 -0.01551
grouppost_w2:syllable21 -0.026155 0.03256
grouppost_w1:syllable22 -0.045119 -0.00208
grouppost_w2:syllable22 -0.014177 0.03235
grouppost_w1:syllable23 -0.041190 0.00467
grouppost_w2:syllable23 -0.009876 0.03507
grouppost_w1:syllable24 -0.039311 0.00632
grouppost_w2:syllable24 -0.007713 0.04145
grouppost_w1:syllable25 -0.042997 0.00102
grouppost_w2:syllable25 -0.003868 0.04092
grouppost_w1:syllable26 -0.043294 0.00120
grouppost_w2:syllable26 -0.008759 0.03980
grouppost_w1:syllable27 -0.040544 0.01104
grouppost_w2:syllable27 -0.007876 0.04854
grouppost_w1:syllable28 -0.048090 -0.00190
grouppost_w2:syllable28 -0.011289 0.03970
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
#DF analysis uses kenward-roger adjustment to take into account small and uneven sample size
#boot is for violations of assumptions
# Obtain estimated marginal means
emm_oft <- emmeans(model_oft, ~ group | syllable) # Pairwise comparisons of syllable effects within each group
head(emm_oft)
group syllable emmean SE df lower.CL upper.CL
control 0 0.156 0.00554 890 0.145 0.167
post_w1 0 0.177 0.00554 890 0.167 0.188
post_w2 0 0.137 0.00602 890 0.126 0.149
control 1 0.138 0.00554 890 0.128 0.149
post_w1 1 0.149 0.00554 890 0.138 0.160
post_w2 1 0.142 0.00602 890 0.131 0.154
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
#kenward-roger is for unequal sample size
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_oft <- contrast(emm_oft, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm, tukey, dunnett, sidak [tukey, holm]
#kenward-roger is for unequal sample size
#holm seems good for our data, check with ilary
summary(pairwise_oft)
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0215 0.00783 878 -2.750 0.0170
control - post_w2 0.0187 0.00818 880 2.290 0.0580
post_w1 - post_w2 0.0402 0.00818 880 4.920 <.0001
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0106 0.00783 878 -1.350 0.3690
control - post_w2 -0.0041 0.00818 880 -0.500 0.8730
post_w1 - post_w2 0.0065 0.00818 880 0.790 0.7070
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0123 0.00783 878 1.580 0.2570
control - post_w2 0.0500 0.00818 880 6.110 <.0001
post_w1 - post_w2 0.0377 0.00818 880 4.600 <.0001
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0055 0.00783 878 -0.700 0.7620
control - post_w2 -0.0316 0.00818 880 -3.870 <.0001
post_w1 - post_w2 -0.0261 0.00818 880 -3.190 0.0040
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0127 0.00783 878 -1.620 0.2360
control - post_w2 -0.0482 0.00818 880 -5.890 <.0001
post_w1 - post_w2 -0.0354 0.00818 880 -4.330 <.0001
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0099 0.00783 878 1.270 0.4120
control - post_w2 0.0018 0.00818 880 0.220 0.9730
post_w1 - post_w2 -0.0081 0.00818 880 -0.990 0.5830
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0048 0.00783 878 -0.610 0.8140
control - post_w2 -0.0233 0.00818 880 -2.840 0.0130
post_w1 - post_w2 -0.0185 0.00818 880 -2.260 0.0620
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0160 0.00783 878 2.040 0.1040
control - post_w2 0.0135 0.00818 880 1.650 0.2270
post_w1 - post_w2 -0.0025 0.00818 880 -0.310 0.9500
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0031 0.00783 878 -0.400 0.9150
control - post_w2 0.0071 0.00818 880 0.870 0.6590
post_w1 - post_w2 0.0103 0.00818 880 1.260 0.4210
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0234 0.00783 878 2.990 0.0080
control - post_w2 0.0293 0.00818 880 3.580 0.0010
post_w1 - post_w2 0.0058 0.00818 880 0.710 0.7580
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0101 0.00799 879 -1.260 0.4170
control - post_w2 -0.0476 0.00834 879 -5.710 <.0001
post_w1 - post_w2 -0.0375 0.00818 880 -4.580 <.0001
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0259 0.00818 880 3.160 0.0050
control - post_w2 0.0340 0.00840 881 4.040 <.0001
post_w1 - post_w2 0.0081 0.00873 881 0.930 0.6230
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0104 0.00815 880 -1.280 0.4060
control - post_w2 -0.0076 0.00834 881 -0.910 0.6320
post_w1 - post_w2 0.0028 0.00834 881 0.340 0.9390
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0026 0.00783 878 0.330 0.9420
control - post_w2 -0.0099 0.00818 880 -1.220 0.4440
post_w1 - post_w2 -0.0125 0.00818 880 -1.530 0.2760
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0058 0.00783 878 -0.730 0.7430
control - post_w2 -0.0073 0.00818 880 -0.900 0.6430
post_w1 - post_w2 -0.0016 0.00818 880 -0.190 0.9800
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0047 0.00834 879 -0.560 0.8400
control - post_w2 -0.0188 0.00852 882 -2.210 0.0700
post_w1 - post_w2 -0.0141 0.00834 881 -1.700 0.2080
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0019 0.00783 878 -0.250 0.9670
control - post_w2 0.0042 0.00818 880 0.510 0.8650
post_w1 - post_w2 0.0061 0.00818 880 0.750 0.7340
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0114 0.00855 880 -1.340 0.3750
control - post_w2 -0.0068 0.00881 883 -0.770 0.7200
post_w1 - post_w2 0.0046 0.00918 882 0.510 0.8690
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0001 0.00873 881 -0.010 1.0000
control - post_w2 -0.0009 0.00918 882 -0.100 0.9950
post_w1 - post_w2 -0.0008 0.00898 880 -0.090 0.9950
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0099 0.00898 884 -1.100 0.5130
control - post_w2 -0.0218 0.00918 884 -2.370 0.0470
post_w1 - post_w2 -0.0119 0.00873 881 -1.360 0.3630
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0152 0.00815 880 1.860 0.1510
control - post_w2 0.0170 0.00912 884 1.870 0.1490
post_w1 - post_w2 0.0019 0.00912 882 0.200 0.9780
syllable = 21:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0162 0.00799 879 2.030 0.1060
control - post_w2 0.0166 0.01140 887 1.450 0.3150
post_w1 - post_w2 0.0004 0.01150 887 0.030 0.9990
syllable = 22:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0003 0.00799 879 0.030 0.9990
control - post_w2 0.0089 0.00881 883 1.010 0.5720
post_w1 - post_w2 0.0086 0.00866 882 0.990 0.5810
syllable = 23:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0018 0.00852 880 -0.210 0.9760
control - post_w2 0.0054 0.00928 884 0.590 0.8270
post_w1 - post_w2 0.0072 0.00928 882 0.780 0.7160
syllable = 24:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0036 0.00855 882 -0.420 0.9060
control - post_w2 0.0017 0.00999 885 0.180 0.9830
post_w1 - post_w2 0.0054 0.01030 883 0.520 0.8610
syllable = 25:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0001 0.00834 881 -0.010 1.0000
control - post_w2 0.0021 0.00855 882 0.240 0.9690
post_w1 - post_w2 0.0021 0.00873 883 0.240 0.9680
syllable = 26:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0012 0.00834 881 -0.140 0.9890
control - post_w2 0.0039 0.00928 882 0.420 0.9080
post_w1 - post_w2 0.0051 0.00912 884 0.560 0.8430
syllable = 27:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0074 0.01030 882 -0.720 0.7530
control - post_w2 -0.0015 0.01070 886 -0.140 0.9900
post_w1 - post_w2 0.0060 0.01030 885 0.580 0.8330
syllable = 28:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0027 0.00893 882 0.300 0.9500
control - post_w2 0.0056 0.00985 887 0.560 0.8390
post_w1 - post_w2 0.0028 0.00985 886 0.290 0.9550
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
#for ggplot below
syllable_labels_oft <- c(
"0" = "0 (sniff_locomotion)",
"1" = "1 (rear_supported)",
"2" = "2 (stand-still)",
"3" = "3 (turn_right_sharp)",
"4" = "4 (turn_left_sharp)",
"5" = "5 (locomotion_sniff_right)",
"6" = "6 (rear_supported_left)",
"7" = "7 (locomotion_sniff_left)",
"8" = "8 (head_dip_left)",
"9" = "9 (turn_sniff_left)",
"10" = "10 (acceleration_left)",
"11" = "11 (turn_sniff_right)",
"12" = "12 (rear_supported_right_multiple)",
"13" = "13 (thigmotaxis_rear)",
"14" = "14 (rear_supported_right_locomotion)",
"15" = "15 (acceleration_right)",
"16" = "16 (locomotion_straight)",
"17" = "17 (rear_supported_left_partial)",
"18" = "18 (rear_supported_left_multiple)",
"19" = "19 (thigomtaxis_locomotion)",
"20" = "20 (rear_supported/unsupported)",
"21" = "21 (head_retract)",
"22" = "22 (head_dip_right)",
"23" = "23 (look_up)",
"24" = "24 (groom/rear)",
"25" = "25 (rear_supported_right)",
"26" = "26 (sniff_up)",
"27" = "27 (rear_supported_left_locomotion)",
"28" = "28 (back_step)"
)
# start to order by control frequency
#extract results from the emmeans
emm_df_oft <- as.data.frame(emm_oft) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_oft
# Get syllables in descending order of emmean from the control group
syllable_order_oft <- emm_df_oft %>%
filter(group == "control") %>%
arrange(desc(emmean)) %>% #computed mean frequency sorted from most to least
pull(syllable) %>% # Extract just the ordered syllable names, this controls x-axis of plot
as.character()
# Reapply the factor with new levels
emm_df_oft <- emm_df_oft %>%
mutate(syllable = factor(syllable, levels = syllable_order_oft))
emm_df_oft
# TESTING THE CONFIDENCE INTERVALS INSTEAD OF SE TO CHECK SYLLABLE 0
plot_oft_test <- ggplot(emm_df_oft, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
#geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - lower.CL, ymax = emmean + upper.CL), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft) +
# Labels for axes and legend
labs(
x = "Syllables",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 18),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_oft <- plot_oft + geom_text(
data = sig_syllables_oft,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "post_w1 - post_w2" ~ 0.24,
contrast == "control - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_oft_test
#ggsave("oft_graph(test_CL).png", plot = plot_oft_test, width = 11, height = 6) #makes spaces visible
#this data will be used for plotting
# Apply the same syllable ordering as in emm_df
# Convert the pairwise results into a data frame using summary
pairwise_results_oft <- summary(pairwise_oft)
# Filter significant results (p-value < 0.05)
sig_results_oft <- pairwise_results_oft[pairwise_results_oft$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_oft <- sig_results_oft %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
sig_syllables_oft <- sig_syllables_oft %>%
mutate(syllable = factor(syllable, levels = levels(emm_df_oft$syllable)))
# Print sig_syllables to check
print(sig_syllables_oft)
#check if factor ordering is same
levels(emm_df_oft$syllable)
[1] "0" "1" "2" "3" "4" "5" "9" "11" "7" "8" "20" "21" "6" "13" "14" "16" "18" "12" "22" "23" "17"
[22] "28" "15" "24" "25" "26" "10" "27" "19"
levels(sig_syllables_oft$syllable)
[1] "0" "1" "2" "3" "4" "5" "9" "11" "7" "8" "20" "21" "6" "13" "14" "16" "18" "12" "22" "23" "17"
[22] "28" "15" "24" "25" "26" "10" "27" "19"
# Create the plot
plot_oft <- ggplot(emm_df_oft, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
#geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft) +
# Labels for axes and legend
labs(
x = "Syllables",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 18),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_oft <- plot_oft + geom_text(
data = sig_syllables_oft,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "post_w1 - post_w2" ~ 0.24,
contrast == "control - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_oft
#ggsave("oft_graph(FINAL).png", plot = plot_oft, width = 11, height = 6) #makes spaces visible
#NOR_ordered_SE
#load results file and make sure headings and levels are established
df_nor <- read.csv("NEW_new_moseq_NOR_stats.csv", header=TRUE)
df_nor$syllable <- factor(df_nor$syllable) # Convert to categorical
df_nor$group <- factor(df_nor$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
#cool fact, code above sets "control" as baseline value as it comes first
df_nor$ID <- factor(df_nor$ID)
str(df_nor)
'data.frame': 1519 obs. of 18 variables:
$ group : Factor w/ 3 levels "control","post_w1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ name : chr "pre-induction-NOR-crop_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction-NOR-crop_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction-NOR-crop_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction-NOR-crop_fixed_Trial 1 - crop_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" ...
$ ID : Factor w/ 13 levels "98","102","112",..: 7 7 7 7 7 7 7 7 7 7 ...
$ syllable : Factor w/ 26 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
$ heading_mean : num 0.40626 0.35599 0.04398 -0.04123 -0.00185 ...
$ heading_std : num 1.72 1.23 1.57 1.58 1.71 ...
$ heading_min : num -3.14 -2.67 -3.12 -3.14 -3.12 ...
$ heading_max : num 3.14 1.66 3.07 3.14 3.14 ...
$ angular_velocity_mean: num -0.2921 -0.1428 1.1289 -0.0214 -0.1102 ...
$ angular_velocity_std : num 15.683 0.437 11.384 14.269 12.245 ...
$ angular_velocity_min : num -314 -3.1 -312.15 -313.79 -5.57 ...
$ angular_velocity_max : num 314.01 0.85 6.01 312.77 312.64 ...
$ velocity_px_s_mean : num 105.4 38.9 194.5 113.2 184.6 ...
$ velocity_px_s_std : num 99 22.9 122 88.3 133 ...
$ velocity_px_s_min : num 0.511 1.975 5.862 2.802 2.926 ...
$ velocity_px_s_max : num 597 176 561 533 636 ...
$ frequency : num 0.1635 0.0433 0.1106 0.1394 0.0673 ...
$ duration : num 1.414 1.147 0.669 2.001 1.89 ...
model_nor <- lmer(frequency ~ group * syllable + (1 | ID), data = df_nor)
boundary (singular) fit: see help('isSingular')
summary(model_nor)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_nor
REML criterion at convergence: -6066
Scaled residuals:
Min 1Q Median 3Q Max
-5.192 -0.457 -0.116 0.370 5.491
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.000000 0.0000
Residual 0.000743 0.0272
Number of obs: 1519, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 2.01e-01 5.34e-03 1.44e+03 37.53 < 2e-16 ***
grouppost_w1 2.66e-03 7.56e-03 1.44e+03 0.35 0.72511
grouppost_w2 -7.63e-02 7.89e-03 1.44e+03 -9.67 < 2e-16 ***
syllable1 -5.55e-02 7.56e-03 1.44e+03 -7.35 3.4e-13 ***
syllable2 -1.28e-01 7.56e-03 1.44e+03 -16.98 < 2e-16 ***
syllable3 -1.28e-01 7.56e-03 1.44e+03 -16.94 < 2e-16 ***
syllable4 -1.40e-01 7.56e-03 1.44e+03 -18.57 < 2e-16 ***
syllable5 -1.59e-01 7.56e-03 1.44e+03 -21.09 < 2e-16 ***
syllable6 -1.83e-01 7.80e-03 1.44e+03 -23.43 < 2e-16 ***
syllable7 -1.67e-01 7.56e-03 1.44e+03 -22.06 < 2e-16 ***
syllable8 -1.60e-01 7.56e-03 1.44e+03 -21.21 < 2e-16 ***
syllable9 -1.64e-01 7.56e-03 1.44e+03 -21.66 < 2e-16 ***
syllable10 -1.83e-01 8.00e-03 1.44e+03 -22.89 < 2e-16 ***
syllable11 -1.85e-01 8.22e-03 1.44e+03 -22.44 < 2e-16 ***
syllable12 -1.66e-01 7.63e-03 1.44e+03 -21.79 < 2e-16 ***
syllable13 -1.87e-01 8.84e-03 1.44e+03 -21.19 < 2e-16 ***
syllable14 -1.87e-01 9.26e-03 1.44e+03 -20.23 < 2e-16 ***
syllable15 -1.77e-01 7.63e-03 1.44e+03 -23.21 < 2e-16 ***
syllable16 -1.77e-01 8.35e-03 1.44e+03 -21.14 < 2e-16 ***
syllable17 -1.84e-01 7.71e-03 1.44e+03 -23.85 < 2e-16 ***
syllable18 -1.90e-01 9.80e-03 1.44e+03 -19.39 < 2e-16 ***
syllable19 -1.92e-01 9.51e-03 1.44e+03 -20.21 < 2e-16 ***
syllable20 -1.75e-01 8.50e-03 1.44e+03 -20.62 < 2e-16 ***
syllable21 -1.91e-01 8.66e-03 1.44e+03 -22.01 < 2e-16 ***
syllable22 -1.81e-01 8.50e-03 1.44e+03 -21.27 < 2e-16 ***
syllable23 -1.89e-01 8.50e-03 1.44e+03 -22.29 < 2e-16 ***
syllable24 -1.90e-01 1.10e-02 1.44e+03 -17.25 < 2e-16 ***
syllable25 -1.79e-01 9.80e-03 1.44e+03 -18.25 < 2e-16 ***
grouppost_w1:syllable1 -4.05e-02 1.07e-02 1.44e+03 -3.79 0.00016 ***
grouppost_w2:syllable1 -3.54e-02 1.12e-02 1.44e+03 -3.16 0.00164 **
grouppost_w1:syllable2 2.12e-02 1.07e-02 1.44e+03 1.99 0.04733 *
grouppost_w2:syllable2 1.10e-01 1.12e-02 1.44e+03 9.89 < 2e-16 ***
grouppost_w1:syllable3 2.40e-03 1.07e-02 1.44e+03 0.22 0.82215
grouppost_w2:syllable3 9.36e-02 1.12e-02 1.44e+03 8.38 < 2e-16 ***
grouppost_w1:syllable4 8.16e-03 1.07e-02 1.44e+03 0.76 0.44529
grouppost_w2:syllable4 6.84e-02 1.12e-02 1.44e+03 6.12 1.2e-09 ***
grouppost_w1:syllable5 1.13e-02 1.07e-02 1.44e+03 1.06 0.29023
grouppost_w2:syllable5 8.76e-02 1.12e-02 1.44e+03 7.85 8.3e-15 ***
grouppost_w1:syllable6 1.06e-02 1.12e-02 1.44e+03 0.94 0.34714
grouppost_w2:syllable6 1.34e-01 1.13e-02 1.44e+03 11.79 < 2e-16 ***
grouppost_w1:syllable7 3.90e-03 1.07e-02 1.44e+03 0.36 0.71559
grouppost_w2:syllable7 8.49e-02 1.12e-02 1.44e+03 7.61 5.0e-14 ***
grouppost_w1:syllable8 3.34e-03 1.07e-02 1.44e+03 0.31 0.75465
grouppost_w2:syllable8 5.96e-02 1.13e-02 1.44e+03 5.26 1.6e-07 ***
grouppost_w1:syllable9 4.50e-03 1.07e-02 1.44e+03 0.42 0.67398
grouppost_w2:syllable9 5.95e-02 1.12e-02 1.44e+03 5.30 1.4e-07 ***
grouppost_w1:syllable10 -3.33e-03 1.11e-02 1.44e+03 -0.30 0.76290
grouppost_w2:syllable10 1.16e-01 1.15e-02 1.44e+03 10.15 < 2e-16 ***
grouppost_w1:syllable11 6.00e-03 1.15e-02 1.44e+03 0.52 0.60318
grouppost_w2:syllable11 1.07e-01 1.18e-02 1.44e+03 9.09 < 2e-16 ***
grouppost_w1:syllable12 -3.04e-03 1.09e-02 1.44e+03 -0.28 0.77949
grouppost_w2:syllable12 6.00e-02 1.15e-02 1.44e+03 5.20 2.3e-07 ***
grouppost_w1:syllable13 3.13e-03 1.22e-02 1.44e+03 0.26 0.79691
grouppost_w2:syllable13 1.00e-01 1.21e-02 1.44e+03 8.30 2.3e-16 ***
grouppost_w1:syllable14 -3.43e-03 1.26e-02 1.44e+03 -0.27 0.78470
grouppost_w2:syllable14 1.07e-01 1.24e-02 1.44e+03 8.67 < 2e-16 ***
grouppost_w1:syllable15 -3.88e-03 1.08e-02 1.44e+03 -0.36 0.71943
grouppost_w2:syllable15 6.69e-02 1.14e-02 1.44e+03 5.89 4.8e-09 ***
grouppost_w1:syllable16 -1.12e-02 1.23e-02 1.44e+03 -0.91 0.36425
grouppost_w2:syllable16 7.13e-02 1.29e-02 1.44e+03 5.54 3.6e-08 ***
grouppost_w1:syllable17 -2.65e-03 1.10e-02 1.44e+03 -0.24 0.80936
grouppost_w2:syllable17 6.86e-02 1.27e-02 1.44e+03 5.41 7.2e-08 ***
grouppost_w1:syllable18 -6.68e-03 1.39e-02 1.44e+03 -0.48 0.63019
grouppost_w2:syllable18 9.03e-02 1.29e-02 1.44e+03 6.99 4.3e-12 ***
grouppost_w1:syllable19 -3.55e-03 1.31e-02 1.44e+03 -0.27 0.78679
grouppost_w2:syllable19 9.31e-02 1.30e-02 1.44e+03 7.19 1.1e-12 ***
grouppost_w1:syllable20 -1.36e-02 1.28e-02 1.44e+03 -1.07 0.28494
grouppost_w2:syllable20 5.92e-02 1.52e-02 1.44e+03 3.90 9.9e-05 ***
grouppost_w1:syllable21 -3.02e-03 1.33e-02 1.44e+03 -0.23 0.82058
grouppost_w2:syllable21 8.29e-02 1.22e-02 1.44e+03 6.82 1.3e-11 ***
grouppost_w1:syllable22 -1.20e-02 1.30e-02 1.44e+03 -0.93 0.35354
grouppost_w2:syllable22 6.69e-02 1.32e-02 1.44e+03 5.08 4.2e-07 ***
grouppost_w1:syllable23 3.45e-04 1.19e-02 1.44e+03 0.03 0.97691
grouppost_w2:syllable23 7.38e-02 1.22e-02 1.44e+03 6.03 2.0e-09 ***
grouppost_w1:syllable24 -9.43e-04 1.50e-02 1.44e+03 -0.06 0.94981
grouppost_w2:syllable24 8.73e-02 1.49e-02 1.44e+03 5.85 6.1e-09 ***
grouppost_w1:syllable25 -1.55e-02 1.44e-02 1.44e+03 -1.08 0.28075
grouppost_w2:syllable25 6.59e-02 1.35e-02 1.44e+03 4.88 1.2e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 78 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#assumption check 1 - Normality of residuals (should be normally distributed) - passes
qqnorm(resid(model_nor))
qqline(resid(model_nor))
#probs a lil' bit non-normal, thus, whe calculating confidence intervals, used "boot" method which assumes non-normality
#Assumption 2 - Homoscedasticity (variance should be consistent) - passes
plot(fitted(model_nor), resid(model_nor))
#violates it, not evenly distributed, thus, Heteroscedasticity
#Assumption 3 - confidence intervals - passes
confint(model_nor, method = "boot")
Computing bootstrap confidence intervals ...
270 message(s): boundary (singular) fit: see help('isSingular')
2.5 % 97.5 %
.sig01 0.00000 0.00256
.sigma 0.02619 0.02825
(Intercept) 0.19026 0.21196
grouppost_w1 -0.01320 0.01756
grouppost_w2 -0.09325 -0.06030
syllable1 -0.07037 -0.04077
syllable2 -0.14321 -0.11356
syllable3 -0.14334 -0.11322
syllable4 -0.15666 -0.12494
syllable5 -0.17348 -0.14302
syllable6 -0.19868 -0.16728
syllable7 -0.18139 -0.15210
syllable8 -0.17601 -0.14622
syllable9 -0.17843 -0.14806
syllable10 -0.19794 -0.16888
syllable11 -0.20075 -0.16809
syllable12 -0.18068 -0.15161
syllable13 -0.20358 -0.17126
syllable14 -0.20500 -0.16985
syllable15 -0.19345 -0.16211
syllable16 -0.19267 -0.16027
syllable17 -0.20077 -0.17041
syllable18 -0.20987 -0.16947
syllable19 -0.20981 -0.17527
syllable20 -0.19270 -0.16111
syllable21 -0.20667 -0.17183
syllable22 -0.19801 -0.16247
syllable23 -0.20590 -0.17425
syllable24 -0.21160 -0.16807
syllable25 -0.19738 -0.15927
grouppost_w1:syllable1 -0.06400 -0.01990
grouppost_w2:syllable1 -0.05591 -0.01457
grouppost_w1:syllable2 0.00136 0.04518
grouppost_w2:syllable2 0.08635 0.13357
grouppost_w1:syllable3 -0.01868 0.02313
grouppost_w2:syllable3 0.07038 0.11357
grouppost_w1:syllable4 -0.01262 0.02922
grouppost_w2:syllable4 0.04761 0.09198
grouppost_w1:syllable5 -0.00988 0.03112
grouppost_w2:syllable5 0.06447 0.11202
grouppost_w1:syllable6 -0.00981 0.03296
grouppost_w2:syllable6 0.11051 0.15564
grouppost_w1:syllable7 -0.01547 0.02571
grouppost_w2:syllable7 0.06137 0.10829
grouppost_w1:syllable8 -0.01846 0.02565
grouppost_w2:syllable8 0.03845 0.08047
grouppost_w1:syllable9 -0.01792 0.02810
grouppost_w2:syllable9 0.03717 0.08041
grouppost_w1:syllable10 -0.02509 0.01846
grouppost_w2:syllable10 0.09456 0.13820
grouppost_w1:syllable11 -0.01847 0.02905
grouppost_w2:syllable11 0.08169 0.12946
grouppost_w1:syllable12 -0.02323 0.01785
grouppost_w2:syllable12 0.03520 0.08412
grouppost_w1:syllable13 -0.01725 0.02610
grouppost_w2:syllable13 0.07614 0.12383
grouppost_w1:syllable14 -0.02628 0.02256
grouppost_w2:syllable14 0.08379 0.13174
grouppost_w1:syllable15 -0.02620 0.01801
grouppost_w2:syllable15 0.04573 0.08947
grouppost_w1:syllable16 -0.03661 0.01299
grouppost_w2:syllable16 0.04370 0.09644
grouppost_w1:syllable17 -0.02529 0.01846
grouppost_w2:syllable17 0.04272 0.09518
grouppost_w1:syllable18 -0.03457 0.02359
grouppost_w2:syllable18 0.06400 0.11697
grouppost_w1:syllable19 -0.02878 0.02040
grouppost_w2:syllable19 0.06936 0.11912
grouppost_w1:syllable20 -0.03763 0.01188
grouppost_w2:syllable20 0.03071 0.08763
grouppost_w1:syllable21 -0.03085 0.02425
grouppost_w2:syllable21 0.06057 0.10504
grouppost_w1:syllable22 -0.03878 0.01486
grouppost_w2:syllable22 0.04354 0.09209
grouppost_w1:syllable23 -0.02258 0.02534
grouppost_w2:syllable23 0.05054 0.09708
grouppost_w1:syllable24 -0.02972 0.02479
grouppost_w2:syllable24 0.05789 0.11545
grouppost_w1:syllable25 -0.04400 0.01259
grouppost_w2:syllable25 0.03888 0.08999
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
#DF analysis uses kenward-roger adjustment to take into account small and uneven sample size
#boot is for violations of assumptions
# Obtain estimated marginal means
emm_nor <- emmeans(model_nor, ~ group | syllable) # Pairwise comparisons of syllable effects within each group
head(emm_nor)
group syllable emmean SE df lower.CL upper.CL
control 0 0.2006 0.00534 1427 0.1901 0.2110
post_w1 0 0.2032 0.00534 1427 0.1927 0.2137
post_w2 0 0.1242 0.00581 1427 0.1128 0.1356
control 1 0.1450 0.00534 1427 0.1346 0.1555
post_w1 1 0.1072 0.00534 1427 0.0967 0.1177
post_w2 1 0.0332 0.00595 1428 0.0216 0.0449
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
#kenward-roger is for unequal sample size
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_nor <- contrast(emm_nor, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm, tukey
#kenward-roger is for unequal sample size
summary(pairwise_nor)
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0027 0.00756 1429 -0.350 0.9340
control - post_w2 0.0763 0.00790 1433 9.670 <.0001
post_w1 - post_w2 0.0790 0.00790 1433 10.010 <.0001
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0378 0.00756 1429 5.000 <.0001
control - post_w2 0.1118 0.00800 1433 13.980 <.0001
post_w1 - post_w2 0.0740 0.00800 1433 9.250 <.0001
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0239 0.00756 1429 -3.160 0.0050
control - post_w2 -0.0341 0.00790 1433 -4.320 <.0001
post_w1 - post_w2 -0.0102 0.00790 1433 -1.290 0.4000
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0051 0.00756 1429 -0.670 0.7810
control - post_w2 -0.0172 0.00790 1433 -2.180 0.0740
post_w1 - post_w2 -0.0122 0.00790 1433 -1.540 0.2710
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0108 0.00756 1429 -1.430 0.3250
control - post_w2 0.0080 0.00790 1433 1.010 0.5710
post_w1 - post_w2 0.0188 0.00790 1433 2.380 0.0460
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0140 0.00756 1429 -1.850 0.1550
control - post_w2 -0.0112 0.00790 1433 -1.420 0.3290
post_w1 - post_w2 0.0027 0.00790 1433 0.350 0.9360
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0132 0.00833 1432 -1.590 0.2510
control - post_w2 -0.0572 0.00813 1433 -7.040 <.0001
post_w1 - post_w2 -0.0440 0.00842 1434 -5.220 <.0001
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0066 0.00756 1429 -0.870 0.6610
control - post_w2 -0.0086 0.00790 1433 -1.090 0.5210
post_w1 - post_w2 -0.0020 0.00790 1433 -0.260 0.9640
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0060 0.00756 1429 -0.790 0.7070
control - post_w2 0.0168 0.00811 1434 2.070 0.0960
post_w1 - post_w2 0.0228 0.00811 1434 2.810 0.0140
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0072 0.00756 1429 -0.950 0.6110
control - post_w2 0.0168 0.00800 1433 2.100 0.0890
post_w1 - post_w2 0.0240 0.00800 1433 3.000 0.0080
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0007 0.00807 1432 0.080 0.9960
control - post_w2 -0.0400 0.00832 1434 -4.810 <.0001
post_w1 - post_w2 -0.0407 0.00797 1433 -5.100 <.0001
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0087 0.00873 1434 -0.990 0.5820
control - post_w2 -0.0306 0.00873 1435 -3.500 0.0010
post_w1 - post_w2 -0.0219 0.00862 1434 -2.550 0.0300
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0004 0.00779 1431 0.050 0.9990
control - post_w2 0.0163 0.00843 1436 1.940 0.1290
post_w1 - post_w2 0.0159 0.00850 1435 1.870 0.1460
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0058 0.00954 1440 -0.610 0.8160
control - post_w2 -0.0238 0.00913 1439 -2.610 0.0250
post_w1 - post_w2 -0.0180 0.00867 1439 -2.080 0.0940
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0008 0.01000 1438 0.080 0.9970
control - post_w2 -0.0309 0.00954 1437 -3.240 0.0030
post_w1 - post_w2 -0.0317 0.00880 1435 -3.600 0.0010
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0012 0.00771 1429 0.160 0.9860
control - post_w2 0.0094 0.00818 1433 1.150 0.4820
post_w1 - post_w2 0.0082 0.00818 1433 1.000 0.5750
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0085 0.00971 1432 0.880 0.6550
control - post_w2 0.0051 0.01020 1437 0.500 0.8710
post_w1 - post_w2 -0.0034 0.01070 1438 -0.320 0.9450
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0000 0.00795 1431 0.000 1.0000
control - post_w2 0.0077 0.00993 1439 0.780 0.7170
post_w1 - post_w2 0.0077 0.01000 1438 0.770 0.7200
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0040 0.01160 1441 0.350 0.9360
control - post_w2 -0.0139 0.01020 1437 -1.360 0.3620
post_w1 - post_w2 -0.0179 0.01020 1440 -1.750 0.1870
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0009 0.01070 1441 0.080 0.9960
control - post_w2 -0.0168 0.01030 1435 -1.630 0.2330
post_w1 - post_w2 -0.0176 0.00985 1441 -1.790 0.1730
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0110 0.01030 1440 1.070 0.5340
control - post_w2 0.0172 0.01300 1439 1.330 0.3810
post_w1 - post_w2 0.0062 0.01360 1441 0.450 0.8930
syllable = 21:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0004 0.01100 1439 0.030 0.9990
control - post_w2 -0.0066 0.00925 1436 -0.710 0.7560
post_w1 - post_w2 -0.0070 0.01070 1440 -0.650 0.7910
syllable = 22:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0094 0.01060 1439 0.890 0.6470
control - post_w2 0.0094 0.01060 1439 0.890 0.6460
post_w1 - post_w2 0.0000 0.01160 1441 0.000 1.0000
syllable = 23:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0030 0.00922 1434 -0.330 0.9430
control - post_w2 0.0025 0.00935 1438 0.270 0.9610
post_w1 - post_w2 0.0055 0.00922 1434 0.600 0.8210
syllable = 24:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0017 0.01290 1439 -0.130 0.9900
control - post_w2 -0.0109 0.01270 1440 -0.860 0.6640
post_w1 - post_w2 -0.0092 0.01190 1440 -0.770 0.7190
syllable = 25:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0129 0.01230 1441 1.050 0.5460
control - post_w2 0.0104 0.01100 1438 0.950 0.6100
post_w1 - post_w2 -0.0025 0.01170 1441 -0.210 0.9760
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
#for ggplot below
syllable_labels_nor <-c(
"0" = "0 (sniff_stationary)",
"1" = "1 (stand-still)",
"2" = "2 (turn_right)",
"3" = "3 (look_up_right)",
"4" = "4 (turn_left)",
"5" = "5 (locomotion_right)",
"6" = "6 (rear_supported_left_traverse)",
"7" = "7 (turn_left_diagonal)",
"8" = "8 (sniff_object)",
"9" = "9 (turn_sniff_left)",
"10" = "10 (turn_left_moderate)",
"11" = "11 (rear_supported_left_locomotion)",
"12" = "12 (sniff_locomotion)",
"13" = "13 (rear_supported_right_locomotion)",
"14" = "14 (acceleration_left)",
"15" = "15 (hunched_groom/stationary_sniff)",
"16" = "16 (look_up)",
"17" = "17 (head_turn_right)",
"18" = "18 (rear_supported_right_traverse)",
"19" = "19 (rear_supported_right_acceleration)",
"20" = "20 (head_dip)",
"21" = "21 (rear_supported_left_acceleration)",
"22" = "22 (groom_curled/supported_rearing)",
"23" = "23 (accelerate_head_retract)",
"24" = "24 (rear_supported_left_acceleration)",
"25" = "25 (groom_corner/climb_object)"
)
# start to order by control frequency
#extract results from the emmeans
emm_df_nor <- as.data.frame(emm_nor) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_nor
# Get syllables in descending order of emmean from the control group
syllable_order_nor <- emm_df_nor %>%
filter(group == "control") %>%
arrange(desc(emmean)) %>% #computed mean frequency sorted from most to least
pull(syllable) %>% # Extract just the ordered syllable names, this controls x-axis of plot
as.character()
# Reapply the factor with new levels
emm_df_nor <- emm_df_nor %>%
mutate(syllable = factor(syllable, levels = syllable_order_nor))
emm_df_nor
#this data will be used for plotting
# Apply the same syllable ordering as in emm_df
# Convert the pairwise results into a data frame using summary
pairwise_results_nor <- summary(pairwise_nor)
# Filter significant results (p-value < 0.05)
sig_results_nor <- pairwise_results_nor[pairwise_results_nor$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_nor <- sig_results_nor %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
sig_syllables_nor <- sig_syllables_nor %>%
mutate(syllable = factor(syllable, levels = levels(emm_df_nor$syllable)))
# Print sig_syllables to check
print(sig_syllables_nor)
#check if factor ordering is same
levels(emm_df_nor$syllable)
[1] "0" "1" "3" "2" "4" "5" "8" "9" "12" "7" "20" "16" "15" "25" "22" "6" "10" "17" "11" "13" "14"
[22] "23" "24" "18" "21" "19"
levels(sig_syllables_nor$syllable)
[1] "0" "1" "3" "2" "4" "5" "8" "9" "12" "7" "20" "16" "15" "25" "22" "6" "10" "17" "11" "13" "14"
[22] "23" "24" "18" "21" "19"
# Create the plot
plot_nor <- ggplot(emm_df_nor, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
#geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_nor) +
# Labels for axes and legend
labs(
x = "Syllables",
y = "Frequency",
color = NULL
) +
ylim(0, 0.4) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 18),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_nor <- plot_nor + geom_text(
data = sig_syllables_nor,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.38,
contrast == "post_w1 - post_w2" ~ 0.34,
contrast == "control - post_w2" ~ 0.30,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_nor
#ggsave("nor_graph(FINAL).png", plot = plot_nor, width = 10, height = 6) #makes spaces visible
#EPM_ordered_SE
#load results file and make sure headings and levels are established
df_epm <- read.csv("new_moseq_EPM_stats.csv", header=TRUE)
df_epm$syllable <- factor(df_epm$syllable) # Convert to categorical
df_epm$group <- factor(df_epm$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
#cool fact, code above sets "control" as baseline value as it comes first
df_epm$ID <- factor(df_epm$ID)
str(df_epm)
'data.frame': 749 obs. of 18 variables:
$ group : Factor w/ 3 levels "control","post_w1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ name : chr "pre-induction_EPM_fixed_1_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction_EPM_fixed_1_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction_EPM_fixed_1_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction_EPM_fixed_1_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" ...
$ ID : Factor w/ 13 levels "98","102","112",..: 7 7 7 7 7 7 7 7 7 7 ...
$ syllable : Factor w/ 21 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
$ heading_mean : num -0.244 -0.375 -0.347 -0.172 -0.538 ...
$ heading_std : num 1.55 1.63 1.57 1.71 1.78 ...
$ heading_min : num -3.14 -3.14 -3.12 -3.13 -3.14 ...
$ heading_max : num 3.13 3.14 3.13 3.14 3.14 ...
$ angular_velocity_mean: num 0.0992 0.0609 -0.3352 0.0486 -0.5683 ...
$ angular_velocity_std : num 6.13 5.06 13.16 16.29 12.91 ...
$ angular_velocity_min : num -4.4 -3.28 -9.11 -313.02 -313.63 ...
$ angular_velocity_max : num 313.61 314.06 313.48 7.33 31.18 ...
$ velocity_px_s_mean : num 58.3 39.9 94.4 91.8 54.2 ...
$ velocity_px_s_std : num 49.3 25.7 66.7 64 37.9 ...
$ velocity_px_s_min : num 1.137 0.19 1.512 0.562 0 ...
$ velocity_px_s_max : num 478 319 494 433 249 ...
$ frequency : num 0.1834 0.1763 0.1217 0.1186 0.0609 ...
$ duration : num 0.452 0.693 0.223 0.247 0.311 ...
model_epm <- lmer(frequency ~ group * syllable + (1 | ID), data = df_epm)
boundary (singular) fit: see help('isSingular')
summary(model_epm)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_epm
REML criterion at convergence: -3596
Scaled residuals:
Min 1Q Median 3Q Max
-4.379 -0.453 -0.087 0.409 4.993
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.000000 0.0000
Residual 0.000247 0.0157
Number of obs: 749, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 0.18844 0.00436 686.00000 43.25 < 2e-16 ***
grouppost_w1 -0.01206 0.00616 686.00000 -1.96 0.0506 .
grouppost_w2 0.00167 0.00661 686.00000 0.25 0.8002
syllable1 -0.05539 0.00616 686.00000 -8.99 < 2e-16 ***
syllable2 -0.07444 0.00616 686.00000 -12.08 < 2e-16 ***
syllable3 -0.07917 0.00616 686.00000 -12.85 < 2e-16 ***
syllable4 -0.11268 0.00616 686.00000 -18.29 < 2e-16 ***
syllable5 -0.13817 0.00616 686.00000 -22.42 < 2e-16 ***
syllable6 -0.14310 0.00616 686.00000 -23.22 < 2e-16 ***
syllable7 -0.14838 0.00616 686.00000 -24.08 < 2e-16 ***
syllable8 -0.15572 0.00616 686.00000 -25.27 < 2e-16 ***
syllable9 -0.16224 0.00616 686.00000 -26.33 < 2e-16 ***
syllable10 -0.17150 0.00616 686.00000 -27.83 < 2e-16 ***
syllable11 -0.16992 0.00616 686.00000 -27.58 < 2e-16 ***
syllable12 -0.17126 0.00616 686.00000 -27.79 < 2e-16 ***
syllable13 -0.16289 0.00616 686.00000 -26.43 < 2e-16 ***
syllable14 -0.17793 0.00616 686.00000 -28.87 < 2e-16 ***
syllable15 -0.17251 0.00616 686.00000 -27.99 < 2e-16 ***
syllable16 -0.18153 0.00616 686.00000 -29.46 < 2e-16 ***
syllable17 -0.18310 0.00629 686.00000 -29.11 < 2e-16 ***
syllable18 -0.17784 0.00616 686.00000 -28.86 < 2e-16 ***
syllable19 -0.18124 0.00616 686.00000 -29.41 < 2e-16 ***
syllable20 -0.18330 0.00616 686.00000 -29.75 < 2e-16 ***
grouppost_w1:syllable1 0.00457 0.00871 686.00000 0.52 0.6001
grouppost_w2:syllable1 -0.01807 0.00935 686.00000 -1.93 0.0536 .
grouppost_w1:syllable2 0.00154 0.00871 686.00000 0.18 0.8594
grouppost_w2:syllable2 -0.00898 0.00935 686.00000 -0.96 0.3369
grouppost_w1:syllable3 0.00410 0.00871 686.00000 0.47 0.6381
grouppost_w2:syllable3 0.00265 0.00935 686.00000 0.28 0.7764
grouppost_w1:syllable4 0.03753 0.00871 686.00000 4.31 1.9e-05 ***
grouppost_w2:syllable4 -0.00325 0.00935 686.00000 -0.35 0.7284
grouppost_w1:syllable5 0.00946 0.00871 686.00000 1.09 0.2780
grouppost_w2:syllable5 0.00910 0.00935 686.00000 0.97 0.3304
grouppost_w1:syllable6 0.01767 0.00871 686.00000 2.03 0.0430 *
grouppost_w2:syllable6 -0.01212 0.00935 686.00000 -1.30 0.1950
grouppost_w1:syllable7 0.02261 0.00871 686.00000 2.59 0.0097 **
grouppost_w2:syllable7 -0.00398 0.00935 686.00000 -0.43 0.6705
grouppost_w1:syllable8 0.01043 0.00871 686.00000 1.20 0.2317
grouppost_w2:syllable8 0.01095 0.00935 686.00000 1.17 0.2418
grouppost_w1:syllable9 0.01134 0.00871 686.00000 1.30 0.1936
grouppost_w2:syllable9 -0.00541 0.00935 686.00000 -0.58 0.5626
grouppost_w1:syllable10 0.02283 0.00871 686.00000 2.62 0.0090 **
grouppost_w2:syllable10 0.00717 0.00935 686.00000 0.77 0.4434
grouppost_w1:syllable11 0.02044 0.00871 686.00000 2.35 0.0193 *
grouppost_w2:syllable11 -0.00406 0.00935 686.00000 -0.43 0.6640
grouppost_w1:syllable12 0.01497 0.00871 686.00000 1.72 0.0864 .
grouppost_w2:syllable12 0.00376 0.00935 686.00000 0.40 0.6879
grouppost_w1:syllable13 0.00351 0.00871 686.00000 0.40 0.6877
grouppost_w2:syllable13 -0.01367 0.00935 686.00000 -1.46 0.1439
grouppost_w1:syllable14 0.00999 0.00871 686.00000 1.15 0.2518
grouppost_w2:syllable14 0.01434 0.00935 686.00000 1.53 0.1254
grouppost_w1:syllable15 0.00702 0.00871 686.00000 0.81 0.4207
grouppost_w2:syllable15 -0.00311 0.00935 686.00000 -0.33 0.7392
grouppost_w1:syllable16 0.01074 0.00871 686.00000 1.23 0.2182
grouppost_w2:syllable16 0.00203 0.00935 686.00000 0.22 0.8278
grouppost_w1:syllable17 0.01468 0.00881 686.00000 1.67 0.0960 .
grouppost_w2:syllable17 0.00001 0.00957 686.00000 0.00 0.9992
grouppost_w1:syllable18 0.00703 0.00871 686.00000 0.81 0.4202
grouppost_w2:syllable18 -0.00766 0.00967 686.00000 -0.79 0.4287
grouppost_w1:syllable19 0.00942 0.00891 686.00000 1.06 0.2909
grouppost_w2:syllable19 -0.00089 0.00949 686.00000 -0.09 0.9253
grouppost_w1:syllable20 0.01214 0.00871 686.00000 1.39 0.1641
grouppost_w2:syllable20 0.00015 0.00935 686.00000 0.02 0.9872
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 63 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#assumption check 1 - Normality of residuals (should be normally distributed) - passes
qqnorm(resid(model_epm))
qqline(resid(model_epm))
#probs a lil' bit non-normal, thus, whe calculating confidence intervals, used "boot" method which assumes non-normality
#Assumption 2 - Homoscedasticity (variance should be consistent) - passes
plot(fitted(model_epm), resid(model_epm))
#violates it, not evenly distributed, thus, Heteroscedasticity
#Assumption 3 - confidence intervals - passes
confint(model_epm, method = "boot")
Computing bootstrap confidence intervals ...
272 message(s): boundary (singular) fit: see help('isSingular')
2.5 % 97.5 %
.sig01 0.000000 0.002032
.sigma 0.014795 0.016566
(Intercept) 0.180119 0.196783
grouppost_w1 -0.025283 0.000518
grouppost_w2 -0.012284 0.015314
syllable1 -0.067957 -0.042981
syllable2 -0.086750 -0.063043
syllable3 -0.090356 -0.066202
syllable4 -0.124620 -0.100864
syllable5 -0.150031 -0.126014
syllable6 -0.154122 -0.129233
syllable7 -0.161073 -0.136745
syllable8 -0.167029 -0.142486
syllable9 -0.174251 -0.150548
syllable10 -0.182655 -0.159577
syllable11 -0.182093 -0.157444
syllable12 -0.181979 -0.159295
syllable13 -0.174099 -0.149750
syllable14 -0.188553 -0.164470
syllable15 -0.183445 -0.161647
syllable16 -0.191898 -0.168612
syllable17 -0.195004 -0.167845
syllable18 -0.189321 -0.166274
syllable19 -0.192466 -0.167749
syllable20 -0.194315 -0.171176
grouppost_w1:syllable1 -0.013489 0.024428
grouppost_w2:syllable1 -0.036361 0.001020
grouppost_w1:syllable2 -0.016973 0.020021
grouppost_w2:syllable2 -0.027919 0.009630
grouppost_w1:syllable3 -0.012779 0.020907
grouppost_w2:syllable3 -0.016255 0.020600
grouppost_w1:syllable4 0.020719 0.057447
grouppost_w2:syllable4 -0.021602 0.014257
grouppost_w1:syllable5 -0.007744 0.026669
grouppost_w2:syllable5 -0.009517 0.026874
grouppost_w1:syllable6 -0.000405 0.034603
grouppost_w2:syllable6 -0.032599 0.006954
grouppost_w1:syllable7 0.005994 0.040872
grouppost_w2:syllable7 -0.021062 0.013559
grouppost_w1:syllable8 -0.006346 0.028381
grouppost_w2:syllable8 -0.007451 0.028208
grouppost_w1:syllable9 -0.004764 0.029290
grouppost_w2:syllable9 -0.024202 0.015102
grouppost_w1:syllable10 0.004906 0.040916
grouppost_w2:syllable10 -0.010358 0.026753
grouppost_w1:syllable11 0.003302 0.037971
grouppost_w2:syllable11 -0.022454 0.013516
grouppost_w1:syllable12 -0.002434 0.032336
grouppost_w2:syllable12 -0.015134 0.022970
grouppost_w1:syllable13 -0.013202 0.019771
grouppost_w2:syllable13 -0.032663 0.004254
grouppost_w1:syllable14 -0.008460 0.025946
grouppost_w2:syllable14 -0.004047 0.032032
grouppost_w1:syllable15 -0.011394 0.023929
grouppost_w2:syllable15 -0.021089 0.015263
grouppost_w1:syllable16 -0.007335 0.028730
grouppost_w2:syllable16 -0.017168 0.020848
grouppost_w1:syllable17 -0.004724 0.033116
grouppost_w2:syllable17 -0.020240 0.018198
grouppost_w1:syllable18 -0.011206 0.023544
grouppost_w2:syllable18 -0.025419 0.012730
grouppost_w1:syllable19 -0.008454 0.028126
grouppost_w2:syllable19 -0.019586 0.018058
grouppost_w1:syllable20 -0.006744 0.030082
grouppost_w2:syllable20 -0.019622 0.020013
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
#DF analysis uses kenward-roger adjustment to take into account small and uneven sample size
#boot is for violations of assumptions
# Obtain estimated marginal means
emm_epm <- emmeans(model_epm, ~ group | syllable) # Pairwise comparisons of syllable effects within each group
head(emm_epm)
group syllable emmean SE df lower.CL upper.CL
control 0 0.188 0.00436 686 0.180 0.197
post_w1 0 0.176 0.00436 686 0.168 0.185
post_w2 0 0.190 0.00497 686 0.180 0.200
control 1 0.133 0.00436 686 0.124 0.142
post_w1 1 0.126 0.00436 686 0.117 0.134
post_w2 1 0.117 0.00497 686 0.107 0.126
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
#kenward-roger is for unequal sample size
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_epm <- contrast(emm_epm, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm, tukey
#kenward-roger is for unequal sample size
summary(pairwise_epm)
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 0.01206 0.00616 674 1.960 0.1240
control - post_w2 -0.00167 0.00661 677 -0.250 0.9650
post_w1 - post_w2 -0.01374 0.00661 677 -2.080 0.0950
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00749 0.00616 674 1.220 0.4440
control - post_w2 0.01639 0.00661 677 2.480 0.0360
post_w1 - post_w2 0.00890 0.00661 677 1.350 0.3700
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 0.01052 0.00616 674 1.710 0.2030
control - post_w2 0.00731 0.00661 677 1.110 0.5110
post_w1 - post_w2 -0.00321 0.00661 677 -0.490 0.8780
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00796 0.00616 674 1.290 0.4000
control - post_w2 -0.00433 0.00661 677 -0.650 0.7900
post_w1 - post_w2 -0.01229 0.00661 677 -1.860 0.1510
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.02546 0.00616 674 -4.130 <.0001
control - post_w2 0.00157 0.00661 677 0.240 0.9690
post_w1 - post_w2 0.02703 0.00661 677 4.090 <.0001
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00260 0.00616 674 0.420 0.9060
control - post_w2 -0.01077 0.00661 677 -1.630 0.2340
post_w1 - post_w2 -0.01338 0.00661 677 -2.020 0.1070
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00560 0.00616 674 -0.910 0.6350
control - post_w2 0.01045 0.00661 677 1.580 0.2550
post_w1 - post_w2 0.01605 0.00661 677 2.430 0.0410
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.01055 0.00616 674 -1.710 0.2020
control - post_w2 0.00230 0.00661 677 0.350 0.9350
post_w1 - post_w2 0.01285 0.00661 677 1.940 0.1270
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00163 0.00616 674 0.260 0.9620
control - post_w2 -0.01262 0.00661 677 -1.910 0.1370
post_w1 - post_w2 -0.01425 0.00661 677 -2.160 0.0800
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00072 0.00616 674 0.120 0.9920
control - post_w2 0.00374 0.00661 677 0.570 0.8380
post_w1 - post_w2 0.00302 0.00661 677 0.460 0.8920
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.01076 0.00616 674 -1.750 0.1890
control - post_w2 -0.00884 0.00661 677 -1.340 0.3750
post_w1 - post_w2 0.00192 0.00661 677 0.290 0.9540
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00837 0.00616 674 -1.360 0.3630
control - post_w2 0.00239 0.00661 677 0.360 0.9310
post_w1 - post_w2 0.01076 0.00661 677 1.630 0.2340
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00290 0.00616 674 -0.470 0.8850
control - post_w2 -0.00543 0.00661 677 -0.820 0.6900
post_w1 - post_w2 -0.00253 0.00661 677 -0.380 0.9230
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00856 0.00616 674 1.390 0.3470
control - post_w2 0.01200 0.00661 677 1.820 0.1650
post_w1 - post_w2 0.00344 0.00661 677 0.520 0.8610
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00207 0.00616 674 0.340 0.9400
control - post_w2 -0.01601 0.00661 677 -2.420 0.0410
post_w1 - post_w2 -0.01808 0.00661 677 -2.740 0.0180
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00504 0.00616 674 0.820 0.6920
control - post_w2 0.00144 0.00661 677 0.220 0.9740
post_w1 - post_w2 -0.00360 0.00661 677 -0.550 0.8490
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00133 0.00616 674 0.220 0.9750
control - post_w2 -0.00371 0.00661 677 -0.560 0.8410
post_w1 - post_w2 -0.00503 0.00661 677 -0.760 0.7270
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00261 0.00629 675 -0.420 0.9090
control - post_w2 -0.00168 0.00693 677 -0.240 0.9680
post_w1 - post_w2 0.00093 0.00682 678 0.140 0.9900
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00504 0.00616 674 0.820 0.6920
control - post_w2 0.00598 0.00706 679 0.850 0.6740
post_w1 - post_w2 0.00095 0.00706 679 0.130 0.9900
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 0.00265 0.00644 676 0.410 0.9110
control - post_w2 -0.00078 0.00682 678 -0.110 0.9930
post_w1 - post_w2 -0.00343 0.00707 678 -0.490 0.8780
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.00007 0.00616 674 -0.010 1.0000
control - post_w2 -0.00182 0.00661 677 -0.280 0.9590
post_w1 - post_w2 -0.00175 0.00661 677 -0.260 0.9620
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 3 estimates
#for ggplot below
syllable_labels_epm <- c(
"0" = "0 (sniff)",
"1" = "1 (stand-still)",
"2" = "2 (sniff_left)",
"3" = "3 (sniff_right)",
"4" = "4 (rear_supported_twist)",
"5" = "5 (stretch-attend)",
"6" = "6 (sniff_up)",
"7" = "7 (head_tilt)",
"8" = "8 (sniff_locomotion)",
"9" = "9 (locomotion_brief)",
"10" = "10 (groom/rear_supported)",
"11" = "11 (rear_supported)",
"12" = "12 (turn_stationary_fast)",
"13" = "13 (sniff_corner)",
"14" = "14 (stretch-attend_angle)",
"15" = "15 (turn_stationary_slow)",
"16" = "16 (stretch-attend_left/right)",
"17" = "17 (rear_supported_high)",
"18" = "18 (head_dip)",
"19" = "19 (sniff_diagonal)",
"20" = "20 (turn_stationary_right)"
)
# start to order by control frequency
#extract results from the emmeans
emm_df_epm <- as.data.frame(emm_epm) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_epm
# Get syllables in descending order of emmean from the control group
syllable_order_epm <- emm_df_epm %>%
filter(group == "control") %>%
arrange(desc(emmean)) %>% #computed mean frequency sorted from most to least
pull(syllable) %>% # Extract just the ordered syllable names, this controls x-axis of plot
as.character()
# Reapply the factor with new levels
emm_df_epm <- emm_df_epm %>%
mutate(syllable = factor(syllable, levels = syllable_order_epm))
emm_df_epm
#this data will be used for plotting
# Apply the same syllable ordering as in emm_df
# Convert the pairwise results into a data frame using summary
pairwise_results_epm <- summary(pairwise_epm)
# Filter significant results (p-value < 0.05)
sig_results_epm <- pairwise_results_epm[pairwise_results_epm$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_epm <- sig_results_epm %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
sig_syllables_epm <- sig_syllables_epm %>%
mutate(syllable = factor(syllable, levels = levels(emm_df_epm$syllable)))
# Print sig_syllables to check
print(sig_syllables_epm)
#check if factor ordering is same
levels(emm_df_epm$syllable)
[1] "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "13" "11" "12" "10" "15" "18" "14" "19" "16" "17" "20"
levels(sig_syllables_epm$syllable)
[1] "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "13" "11" "12" "10" "15" "18" "14" "19" "16" "17" "20"
# Create the plot
plot_epm <- ggplot(emm_df_epm, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
#geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_epm) +
# Labels for axes and legend
labs(
x = "Syllables",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 18),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_epm <- plot_epm + geom_text(
data = sig_syllables_epm,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.30,
contrast == "post_w1 - post_w2" ~ 0.26,
contrast == "control - post_w2" ~ 0.22,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_epm
#ggsave("epm_graph(FINAL).png", plot = plot_epm, width = 10, height = 6) #makes spaces visible
#3CT_ordered_SE
#load results file and make sure headings and levels are established
df_3ct <- read.csv("new_moseq_3CT_stats.csv", header=TRUE)
df_3ct$syllable <- factor(df_3ct$syllable) # Convert to categorical
df_3ct$group <- factor(df_3ct$group, levels = c("control", "post_w1", "post_w2")) #factor level categorical
#cool fact, code above sets "control" as baseline value as it comes first
df_3ct$ID <- factor(df_3ct$ID)
str(df_3ct)
'data.frame': 4219 obs. of 18 variables:
$ group : Factor w/ 3 levels "control","post_w1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ name : chr "pre-induction_3CT_fixed_10_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction_3CT_fixed_10_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction_3CT_fixed_10_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" "pre-induction_3CT_fixed_10_superanimal_topviewmouse_snapshot-detector-004_snapshot-004_animal0" ...
$ ID : Factor w/ 13 levels "98","102","112",..: 9 9 9 9 9 9 9 9 9 9 ...
$ syllable : Factor w/ 44 levels "0","1","2","3",..: 1 2 3 4 5 6 7 8 9 10 ...
$ heading_mean : num -0.1041 -0.0753 -0.093 -1.296 0.2046 ...
$ heading_std : num 1.64 1.72 1.77 1.53 1.76 ...
$ heading_min : num -3.13 -3.14 -2.56 -3.14 -3.13 ...
$ heading_max : num 3.14 3.08 2.54 3.14 3.14 ...
$ angular_velocity_mean: num 0.4855 -0.0114 0.1312 -0.7594 0.0241 ...
$ angular_velocity_std : num 12.463 0.395 2.743 11.658 16.018 ...
$ angular_velocity_min : num -312.17 -2.41 -24.2 -4.13 -4.09 ...
$ angular_velocity_max : num 313.18 3.13 2.68 310.36 313.44 ...
$ velocity_px_s_mean : num 102.8 41.7 250.4 188.9 100.5 ...
$ velocity_px_s_std : num 80.3 26.2 139.5 118.5 84.2 ...
$ velocity_px_s_min : num 0.102 1.303 25.722 5.766 2.06 ...
$ velocity_px_s_max : num 541 282 715 564 571 ...
$ frequency : num 0.1029 0.12 0.04 0.0514 0.08 ...
$ duration : num 1.412 1.085 0.174 0.806 1.099 ...
model_3ct <- lmer(frequency ~ group * syllable + (1 | ID), data = df_3ct)
boundary (singular) fit: see help('isSingular')
summary(model_3ct)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: frequency ~ group * syllable + (1 | ID)
Data: df_3ct
REML criterion at convergence: -23662
Scaled residuals:
Min 1Q Median 3Q Max
-4.784 -0.480 -0.094 0.419 9.838
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.00000 0.0000
Residual 0.00016 0.0127
Number of obs: 4219, groups: ID, 13
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 8.37e-02 2.03e-03 4.09e+03 41.26 < 2e-16 ***
grouppost_w1 -1.99e-02 2.87e-03 4.09e+03 -6.95 4.3e-12 ***
grouppost_w2 -3.96e-03 3.29e-03 4.09e+03 -1.21 0.22794
syllable1 5.25e-03 2.87e-03 4.09e+03 1.83 0.06705 .
syllable2 -4.86e-02 2.87e-03 4.09e+03 -16.96 < 2e-16 ***
syllable3 -4.35e-02 2.87e-03 4.09e+03 -15.17 < 2e-16 ***
syllable4 -3.76e-02 2.87e-03 4.09e+03 -13.10 < 2e-16 ***
syllable5 -4.69e-02 2.87e-03 4.09e+03 -16.36 < 2e-16 ***
syllable6 -5.47e-02 2.89e-03 4.09e+03 -18.94 < 2e-16 ***
syllable7 -4.92e-02 2.87e-03 4.09e+03 -17.15 < 2e-16 ***
syllable8 -5.17e-02 2.87e-03 4.09e+03 -18.02 < 2e-16 ***
syllable9 -5.09e-02 2.87e-03 4.09e+03 -17.74 < 2e-16 ***
syllable10 -5.47e-02 2.87e-03 4.09e+03 -19.09 < 2e-16 ***
syllable11 -6.09e-02 2.87e-03 4.09e+03 -21.25 < 2e-16 ***
syllable12 -5.91e-02 2.87e-03 4.09e+03 -20.62 < 2e-16 ***
syllable13 -5.29e-02 2.87e-03 4.09e+03 -18.45 < 2e-16 ***
syllable14 -5.82e-02 2.87e-03 4.09e+03 -20.29 < 2e-16 ***
syllable15 -6.00e-02 2.87e-03 4.09e+03 -20.92 < 2e-16 ***
syllable16 -6.28e-02 2.89e-03 4.09e+03 -21.77 < 2e-16 ***
syllable17 -5.75e-02 2.87e-03 4.09e+03 -20.05 < 2e-16 ***
syllable18 -6.17e-02 2.87e-03 4.09e+03 -21.51 < 2e-16 ***
syllable19 -6.62e-02 2.87e-03 4.09e+03 -23.09 < 2e-16 ***
syllable20 -6.46e-02 2.89e-03 4.09e+03 -22.40 < 2e-16 ***
syllable21 -7.15e-02 2.91e-03 4.09e+03 -24.60 < 2e-16 ***
syllable22 -7.16e-02 2.87e-03 4.09e+03 -24.96 < 2e-16 ***
syllable23 -6.70e-02 2.87e-03 4.09e+03 -23.38 < 2e-16 ***
syllable24 -6.90e-02 2.91e-03 4.09e+03 -23.75 < 2e-16 ***
syllable25 -6.11e-02 2.91e-03 4.09e+03 -21.03 < 2e-16 ***
syllable26 -6.38e-02 3.02e-03 4.09e+03 -21.11 < 2e-16 ***
syllable27 -7.23e-02 2.93e-03 4.09e+03 -24.69 < 2e-16 ***
syllable28 -6.93e-02 2.89e-03 4.09e+03 -24.01 < 2e-16 ***
syllable29 -7.25e-02 2.93e-03 4.09e+03 -24.79 < 2e-16 ***
syllable30 -7.29e-02 2.91e-03 4.09e+03 -25.09 < 2e-16 ***
syllable31 -7.29e-02 2.87e-03 4.09e+03 -25.43 < 2e-16 ***
syllable32 -7.27e-02 2.87e-03 4.09e+03 -25.34 < 2e-16 ***
syllable33 -7.19e-02 2.87e-03 4.09e+03 -25.07 < 2e-16 ***
syllable34 -7.61e-02 2.91e-03 4.09e+03 -26.19 < 2e-16 ***
syllable35 -7.56e-02 2.99e-03 4.09e+03 -25.25 < 2e-16 ***
syllable36 -7.61e-02 2.95e-03 4.09e+03 -25.83 < 2e-16 ***
syllable37 -7.75e-02 2.99e-03 4.09e+03 -25.87 < 2e-16 ***
syllable38 -7.20e-02 3.02e-03 4.09e+03 -23.85 < 2e-16 ***
syllable39 -7.71e-02 2.99e-03 4.09e+03 -25.74 < 2e-16 ***
syllable40 -7.78e-02 3.24e-03 4.09e+03 -23.98 < 2e-16 ***
syllable41 -7.53e-02 3.21e-03 4.09e+03 -23.48 < 2e-16 ***
syllable42 -7.75e-02 3.38e-03 4.09e+03 -22.97 < 2e-16 ***
syllable43 -7.73e-02 3.10e-03 4.09e+03 -24.89 < 2e-16 ***
grouppost_w1:syllable1 -2.24e-03 4.06e-03 4.09e+03 -0.55 0.58044
grouppost_w2:syllable1 -3.36e-02 4.65e-03 4.09e+03 -7.24 5.4e-13 ***
grouppost_w1:syllable2 2.70e-02 4.06e-03 4.09e+03 6.66 3.1e-11 ***
grouppost_w2:syllable2 1.38e-02 4.65e-03 4.09e+03 2.96 0.00305 **
grouppost_w1:syllable3 8.12e-03 4.06e-03 4.09e+03 2.00 0.04537 *
grouppost_w2:syllable3 1.47e-02 4.65e-03 4.09e+03 3.16 0.00159 **
grouppost_w1:syllable4 8.62e-03 4.06e-03 4.09e+03 2.13 0.03364 *
grouppost_w2:syllable4 -7.19e-03 4.65e-03 4.09e+03 -1.55 0.12164
grouppost_w1:syllable5 1.99e-02 4.06e-03 4.09e+03 4.90 9.8e-07 ***
grouppost_w2:syllable5 8.64e-03 4.65e-03 4.09e+03 1.86 0.06297 .
grouppost_w1:syllable6 4.05e-02 4.07e-03 4.09e+03 9.95 < 2e-16 ***
grouppost_w2:syllable6 1.08e-02 4.66e-03 4.09e+03 2.33 0.01990 *
grouppost_w1:syllable7 2.28e-02 4.06e-03 4.09e+03 5.63 1.9e-08 ***
grouppost_w2:syllable7 1.05e-02 4.65e-03 4.09e+03 2.26 0.02363 *
grouppost_w1:syllable8 3.25e-02 4.06e-03 4.09e+03 8.02 1.4e-15 ***
grouppost_w2:syllable8 -2.46e-03 4.65e-03 4.09e+03 -0.53 0.59689
grouppost_w1:syllable9 2.20e-02 4.06e-03 4.09e+03 5.42 6.2e-08 ***
grouppost_w2:syllable9 7.85e-03 4.65e-03 4.09e+03 1.69 0.09104 .
grouppost_w1:syllable10 1.38e-02 4.07e-03 4.09e+03 3.38 0.00073 ***
grouppost_w2:syllable10 1.19e-02 4.65e-03 4.09e+03 2.57 0.01019 *
grouppost_w1:syllable11 2.63e-02 4.06e-03 4.09e+03 6.49 9.3e-11 ***
grouppost_w2:syllable11 1.77e-02 4.65e-03 4.09e+03 3.81 0.00014 ***
grouppost_w1:syllable12 2.13e-02 4.06e-03 4.09e+03 5.25 1.6e-07 ***
grouppost_w2:syllable12 1.75e-02 4.65e-03 4.09e+03 3.76 0.00017 ***
grouppost_w1:syllable13 2.24e-02 4.06e-03 4.09e+03 5.53 3.3e-08 ***
grouppost_w2:syllable13 -1.13e-02 4.65e-03 4.09e+03 -2.43 0.01517 *
grouppost_w1:syllable14 2.56e-02 4.06e-03 4.09e+03 6.31 3.2e-10 ***
grouppost_w2:syllable14 5.06e-04 4.65e-03 4.09e+03 0.11 0.91331
grouppost_w1:syllable15 1.98e-02 4.06e-03 4.09e+03 4.88 1.1e-06 ***
grouppost_w2:syllable15 9.54e-03 4.65e-03 4.09e+03 2.05 0.04017 *
grouppost_w1:syllable16 3.16e-02 4.07e-03 4.09e+03 7.77 1.0e-14 ***
grouppost_w2:syllable16 -5.34e-05 4.66e-03 4.09e+03 -0.01 0.99085
grouppost_w1:syllable17 1.78e-02 4.06e-03 4.09e+03 4.39 1.2e-05 ***
grouppost_w2:syllable17 -7.72e-03 4.65e-03 4.09e+03 -1.66 0.09682 .
grouppost_w1:syllable18 1.63e-02 4.06e-03 4.09e+03 4.02 5.9e-05 ***
grouppost_w2:syllable18 5.19e-03 4.65e-03 4.09e+03 1.12 0.26394
grouppost_w1:syllable19 1.81e-02 4.06e-03 4.09e+03 4.47 8.1e-06 ***
grouppost_w2:syllable19 1.55e-02 4.65e-03 4.09e+03 3.33 0.00089 ***
grouppost_w1:syllable20 1.28e-02 4.08e-03 4.09e+03 3.14 0.00171 **
grouppost_w2:syllable20 1.12e-02 4.66e-03 4.09e+03 2.41 0.01582 *
grouppost_w1:syllable21 2.31e-02 4.10e-03 4.09e+03 5.65 1.7e-08 ***
grouppost_w2:syllable21 1.08e-02 4.70e-03 4.09e+03 2.30 0.02152 *
grouppost_w1:syllable22 2.75e-02 4.07e-03 4.09e+03 6.77 1.5e-11 ***
grouppost_w2:syllable22 5.62e-03 4.68e-03 4.09e+03 1.20 0.22968
grouppost_w1:syllable23 1.45e-02 4.08e-03 4.09e+03 3.56 0.00038 ***
grouppost_w2:syllable23 6.07e-03 4.68e-03 4.09e+03 1.30 0.19417
grouppost_w1:syllable24 2.13e-02 4.08e-03 4.09e+03 5.21 2.0e-07 ***
grouppost_w2:syllable24 4.00e-03 4.67e-03 4.09e+03 0.86 0.39132
grouppost_w1:syllable25 9.58e-03 4.08e-03 4.09e+03 2.35 0.01905 *
grouppost_w2:syllable25 -8.30e-03 4.70e-03 4.09e+03 -1.77 0.07752 .
grouppost_w1:syllable26 1.27e-02 4.21e-03 4.09e+03 3.02 0.00256 **
grouppost_w2:syllable26 2.32e-03 4.97e-03 4.09e+03 0.47 0.64034
grouppost_w1:syllable27 2.57e-02 4.10e-03 4.09e+03 6.27 3.9e-10 ***
grouppost_w2:syllable27 5.53e-03 4.82e-03 4.09e+03 1.15 0.25199
grouppost_w1:syllable28 1.51e-02 4.07e-03 4.09e+03 3.70 0.00022 ***
grouppost_w2:syllable28 3.72e-03 4.69e-03 4.09e+03 0.79 0.42710
grouppost_w1:syllable29 2.53e-02 4.17e-03 4.09e+03 6.08 1.3e-09 ***
grouppost_w2:syllable29 8.57e-03 4.91e-03 4.09e+03 1.74 0.08136 .
grouppost_w1:syllable30 2.00e-02 4.08e-03 4.09e+03 4.89 1.1e-06 ***
grouppost_w2:syllable30 8.99e-03 4.67e-03 4.09e+03 1.92 0.05435 .
grouppost_w1:syllable31 2.22e-02 4.06e-03 4.09e+03 5.47 4.7e-08 ***
grouppost_w2:syllable31 4.79e-03 4.65e-03 4.09e+03 1.03 0.30232
grouppost_w1:syllable32 1.96e-02 4.06e-03 4.09e+03 4.82 1.5e-06 ***
grouppost_w2:syllable32 4.52e-03 4.68e-03 4.09e+03 0.97 0.33395
grouppost_w1:syllable33 1.70e-02 4.06e-03 4.09e+03 4.19 2.8e-05 ***
grouppost_w2:syllable33 3.90e-03 4.65e-03 4.09e+03 0.84 0.40067
grouppost_w1:syllable34 2.25e-02 4.16e-03 4.09e+03 5.42 6.3e-08 ***
grouppost_w2:syllable34 4.47e-03 4.85e-03 4.09e+03 0.92 0.35679
grouppost_w1:syllable35 2.44e-02 4.19e-03 4.09e+03 5.82 6.4e-09 ***
grouppost_w2:syllable35 -2.84e-04 5.01e-03 4.09e+03 -0.06 0.95470
grouppost_w1:syllable36 2.09e-02 4.19e-03 4.09e+03 5.00 6.0e-07 ***
grouppost_w2:syllable36 4.47e-03 4.88e-03 4.09e+03 0.92 0.35945
grouppost_w1:syllable37 2.00e-02 4.20e-03 4.09e+03 4.76 2.0e-06 ***
grouppost_w2:syllable37 5.71e-03 4.79e-03 4.09e+03 1.19 0.23293
grouppost_w1:syllable38 1.52e-02 4.35e-03 4.09e+03 3.50 0.00047 ***
grouppost_w2:syllable38 -2.77e-03 5.51e-03 4.09e+03 -0.50 0.61554
grouppost_w1:syllable39 1.90e-02 4.34e-03 4.09e+03 4.37 1.3e-05 ***
grouppost_w2:syllable39 5.15e-03 4.73e-03 4.09e+03 1.09 0.27557
grouppost_w1:syllable40 2.27e-02 4.49e-03 4.09e+03 5.06 4.3e-07 ***
grouppost_w2:syllable40 5.06e-03 4.98e-03 4.09e+03 1.02 0.31004
grouppost_w1:syllable41 1.89e-02 4.42e-03 4.09e+03 4.28 1.9e-05 ***
grouppost_w2:syllable41 7.00e-03 5.33e-03 4.09e+03 1.31 0.18901
grouppost_w1:syllable42 2.21e-02 4.55e-03 4.09e+03 4.85 1.3e-06 ***
grouppost_w2:syllable42 4.88e-03 5.19e-03 4.09e+03 0.94 0.34768
grouppost_w1:syllable43 2.01e-02 4.30e-03 4.09e+03 4.69 2.9e-06 ***
grouppost_w2:syllable43 2.07e-03 4.86e-03 4.09e+03 0.43 0.66942
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation matrix not shown by default, as p = 132 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#assumption check 1 - Normality of residuals (should be normally distributed) - passes
qqnorm(resid(model_3ct))
qqline(resid(model_3ct))
#probs a lil' bit non-normal, thus, whe calculating confidence intervals, used "boot" method which assumes non-normality
#Assumption 2 - Homoscedasticity (variance should be consistent) - passes
plot(fitted(model_3ct), resid(model_3ct))
#violates it, not evenly distributed, thus, Heteroscedasticity
#Assumption 3 - confidence intervals - passes
confint(model_3ct, method = "boot")
Computing bootstrap confidence intervals ...
297 message(s): boundary (singular) fit: see help('isSingular')
1 warning(s): Model failed to converge with max|grad| = 0.00297061 (tol = 0.002, component 1)
2.5 % 97.5 %
.sig01 0.000000 0.00069
.sigma 0.012363 0.01293
(Intercept) 0.079602 0.08753
grouppost_w1 -0.026247 -0.01376
grouppost_w2 -0.010970 0.00220
syllable1 -0.000712 0.01067
syllable2 -0.054169 -0.04302
syllable3 -0.048890 -0.03802
syllable4 -0.043130 -0.03242
syllable5 -0.053045 -0.04110
syllable6 -0.060007 -0.04876
syllable7 -0.054388 -0.04394
syllable8 -0.057277 -0.04614
syllable9 -0.056278 -0.04530
syllable10 -0.059913 -0.04866
syllable11 -0.066602 -0.05527
syllable12 -0.064286 -0.05365
syllable13 -0.058760 -0.04710
syllable14 -0.063292 -0.05307
syllable15 -0.065715 -0.05453
syllable16 -0.068678 -0.05658
syllable17 -0.063174 -0.05183
syllable18 -0.067437 -0.05633
syllable19 -0.072144 -0.06053
syllable20 -0.070511 -0.05909
syllable21 -0.077509 -0.06570
syllable22 -0.077575 -0.06561
syllable23 -0.072351 -0.06144
syllable24 -0.074734 -0.06353
syllable25 -0.066854 -0.05541
syllable26 -0.069561 -0.05799
syllable27 -0.077683 -0.06584
syllable28 -0.075048 -0.06365
syllable29 -0.078448 -0.06640
syllable30 -0.078432 -0.06716
syllable31 -0.078789 -0.06790
syllable32 -0.078164 -0.06751
syllable33 -0.078042 -0.06655
syllable34 -0.082139 -0.07043
syllable35 -0.081950 -0.06965
syllable36 -0.081684 -0.07037
syllable37 -0.083769 -0.07159
syllable38 -0.078034 -0.06582
syllable39 -0.082590 -0.07121
syllable40 -0.083678 -0.07070
syllable41 -0.082072 -0.06885
syllable42 -0.083450 -0.07035
syllable43 -0.083179 -0.07135
grouppost_w1:syllable1 -0.010345 0.00666
grouppost_w2:syllable1 -0.042647 -0.02292
grouppost_w1:syllable2 0.018935 0.03445
grouppost_w2:syllable2 0.004993 0.02383
grouppost_w1:syllable3 -0.000129 0.01663
grouppost_w2:syllable3 0.005810 0.02389
grouppost_w1:syllable4 0.000674 0.01652
grouppost_w2:syllable4 -0.016128 0.00209
grouppost_w1:syllable5 0.011426 0.02817
grouppost_w2:syllable5 -0.000740 0.01749
grouppost_w1:syllable6 0.032697 0.04823
grouppost_w2:syllable6 0.001698 0.01963
grouppost_w1:syllable7 0.015330 0.03027
grouppost_w2:syllable7 0.002392 0.02015
grouppost_w1:syllable8 0.024460 0.04127
grouppost_w2:syllable8 -0.010716 0.00710
grouppost_w1:syllable9 0.013937 0.03038
grouppost_w2:syllable9 -0.000771 0.01664
grouppost_w1:syllable10 0.005486 0.02233
grouppost_w2:syllable10 0.003205 0.02098
grouppost_w1:syllable11 0.018200 0.03440
grouppost_w2:syllable11 0.008258 0.02665
grouppost_w1:syllable12 0.013788 0.02906
grouppost_w2:syllable12 0.008873 0.02713
grouppost_w1:syllable13 0.013750 0.03076
grouppost_w2:syllable13 -0.020299 -0.00204
grouppost_w1:syllable14 0.017715 0.03310
grouppost_w2:syllable14 -0.008725 0.01015
grouppost_w1:syllable15 0.012416 0.02749
grouppost_w2:syllable15 0.000758 0.01874
grouppost_w1:syllable16 0.022902 0.04020
grouppost_w2:syllable16 -0.009273 0.00987
grouppost_w1:syllable17 0.010144 0.02589
grouppost_w2:syllable17 -0.017641 0.00119
grouppost_w1:syllable18 0.008142 0.02453
grouppost_w2:syllable18 -0.003739 0.01464
grouppost_w1:syllable19 0.010365 0.02642
grouppost_w2:syllable19 0.006176 0.02552
grouppost_w1:syllable20 0.005007 0.02127
grouppost_w2:syllable20 0.002244 0.02078
grouppost_w1:syllable21 0.014645 0.03118
grouppost_w2:syllable21 0.002399 0.02089
grouppost_w1:syllable22 0.019726 0.03598
grouppost_w2:syllable22 -0.003159 0.01467
grouppost_w1:syllable23 0.006438 0.02324
grouppost_w2:syllable23 -0.004003 0.01485
grouppost_w1:syllable24 0.013470 0.02940
grouppost_w2:syllable24 -0.005049 0.01412
grouppost_w1:syllable25 0.001141 0.01809
grouppost_w2:syllable25 -0.018200 0.00179
grouppost_w1:syllable26 0.003805 0.02126
grouppost_w2:syllable26 -0.007307 0.01193
grouppost_w1:syllable27 0.017028 0.03424
grouppost_w2:syllable27 -0.003660 0.01423
grouppost_w1:syllable28 0.006237 0.02327
grouppost_w2:syllable28 -0.005252 0.01438
grouppost_w1:syllable29 0.016554 0.03355
grouppost_w2:syllable29 -0.000421 0.01853
grouppost_w1:syllable30 0.011877 0.02843
grouppost_w2:syllable30 -0.000112 0.01847
grouppost_w1:syllable31 0.014265 0.03035
grouppost_w2:syllable31 -0.003956 0.01402
grouppost_w1:syllable32 0.011335 0.02772
grouppost_w2:syllable32 -0.005077 0.01437
grouppost_w1:syllable33 0.008187 0.02562
grouppost_w2:syllable33 -0.005567 0.01342
grouppost_w1:syllable34 0.014718 0.03079
grouppost_w2:syllable34 -0.004490 0.01389
grouppost_w1:syllable35 0.015905 0.03364
grouppost_w2:syllable35 -0.010660 0.00980
grouppost_w1:syllable36 0.011882 0.02951
grouppost_w2:syllable36 -0.005269 0.01317
grouppost_w1:syllable37 0.012017 0.02856
grouppost_w2:syllable37 -0.003264 0.01589
grouppost_w1:syllable38 0.006275 0.02468
grouppost_w2:syllable38 -0.014328 0.00813
grouppost_w1:syllable39 0.009876 0.02742
grouppost_w2:syllable39 -0.003212 0.01596
grouppost_w1:syllable40 0.013228 0.03080
grouppost_w2:syllable40 -0.005572 0.01441
grouppost_w1:syllable41 0.009523 0.02855
grouppost_w2:syllable41 -0.002925 0.01825
grouppost_w1:syllable42 0.012447 0.03130
grouppost_w2:syllable42 -0.005260 0.01455
grouppost_w1:syllable43 0.011021 0.02930
grouppost_w2:syllable43 -0.006729 0.01194
#if CI includes zero between 2.5% and 97.5% then that effect is not statistically significant.
#DF analysis uses kenward-roger adjustment to take into account small and uneven sample size
#boot is for violations of assumptions
# Obtain estimated marginal means
#emm_3ct <- emmeans(model_3ct, ~ group | syllable, lmerTest.limit = 4219)
emm_3ct <- emmeans(model_3ct, ~ group | syllable) # Pairwise comparisons of syllable effects within each group
Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
To enable adjustments, add the argument 'pbkrtest.limit = 4219' (or larger)
[or, globally, 'set emm_options(pbkrtest.limit = 4219)' or larger];
but be warned that this may result in large computation time and memory use.
Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
To enable adjustments, add the argument 'lmerTest.limit = 4219' (or larger)
[or, globally, 'set emm_options(lmerTest.limit = 4219)' or larger];
but be warned that this may result in large computation time and memory use.
head(emm_3ct)
group syllable emmean SE df asymp.LCL asymp.UCL
control 0 0.0837 0.00203 Inf 0.0797 0.0876
post_w1 0 0.0637 0.00203 Inf 0.0598 0.0677
post_w2 0 0.0797 0.00258 Inf 0.0746 0.0848
control 1 0.0889 0.00203 Inf 0.0849 0.0929
post_w1 1 0.0667 0.00203 Inf 0.0628 0.0707
post_w2 1 0.0513 0.00258 Inf 0.0462 0.0564
Degrees-of-freedom method: asymptotic
Confidence level used: 0.95
#kenward-roger is for unequal sample size
#pairwise comparison with tukey, due to lots of syllable comparisons (more tests)
pairwise_3ct <- contrast(emm_3ct, method = "pairwise", adjust = "tukey") #bonferroni, Satterthwaite, Kenward-Roger, holm, tukey
#kenward-roger is for unequal sample size
summary(pairwise_3ct)
syllable = 0:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0199 0.00287 Inf 6.950 <.0001
control - post_w2 0.0040 0.00329 Inf 1.210 0.4500
post_w1 - post_w2 -0.0160 0.00329 Inf -4.860 <.0001
syllable = 1:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0222 0.00287 Inf 7.730 <.0001
control - post_w2 0.0376 0.00329 Inf 11.440 <.0001
post_w1 - post_w2 0.0154 0.00329 Inf 4.700 <.0001
syllable = 2:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0071 0.00287 Inf -2.470 0.0360
control - post_w2 -0.0098 0.00329 Inf -2.990 0.0080
post_w1 - post_w2 -0.0027 0.00329 Inf -0.830 0.6830
syllable = 3:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0118 0.00287 Inf 4.120 <.0001
control - post_w2 -0.0107 0.00329 Inf -3.260 0.0030
post_w1 - post_w2 -0.0225 0.00329 Inf -6.860 <.0001
syllable = 4:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0113 0.00287 Inf 3.940 <.0001
control - post_w2 0.0112 0.00329 Inf 3.400 0.0020
post_w1 - post_w2 -0.0001 0.00329 Inf -0.050 0.9990
syllable = 5:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0000 0.00287 Inf 0.010 1.0000
control - post_w2 -0.0047 0.00329 Inf -1.420 0.3280
post_w1 - post_w2 -0.0047 0.00329 Inf -1.440 0.3230
syllable = 6:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0206 0.00289 Inf -7.130 <.0001
control - post_w2 -0.0069 0.00330 Inf -2.090 0.0930
post_w1 - post_w2 0.0137 0.00329 Inf 4.170 <.0001
syllable = 7:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0029 0.00287 Inf -1.010 0.5680
control - post_w2 -0.0066 0.00329 Inf -2.000 0.1130
post_w1 - post_w2 -0.0037 0.00329 Inf -1.110 0.5070
syllable = 8:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0126 0.00287 Inf -4.390 <.0001
control - post_w2 0.0064 0.00329 Inf 1.950 0.1240
post_w1 - post_w2 0.0190 0.00329 Inf 5.790 <.0001
syllable = 9:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0021 0.00287 Inf -0.720 0.7520
control - post_w2 -0.0039 0.00329 Inf -1.180 0.4620
post_w1 - post_w2 -0.0018 0.00329 Inf -0.560 0.8430
syllable = 10:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0062 0.00289 Inf 2.140 0.0820
control - post_w2 -0.0080 0.00329 Inf -2.430 0.0400
post_w1 - post_w2 -0.0142 0.00330 Inf -4.290 <.0001
syllable = 11:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0064 0.00287 Inf -2.240 0.0650
control - post_w2 -0.0138 0.00329 Inf -4.190 <.0001
post_w1 - post_w2 -0.0073 0.00329 Inf -2.230 0.0660
syllable = 12:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0014 0.00287 Inf -0.480 0.8820
control - post_w2 -0.0135 0.00329 Inf -4.110 <.0001
post_w1 - post_w2 -0.0121 0.00329 Inf -3.690 0.0010
syllable = 13:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0025 0.00287 Inf -0.880 0.6530
control - post_w2 0.0152 0.00329 Inf 4.640 <.0001
post_w1 - post_w2 0.0178 0.00329 Inf 5.410 <.0001
syllable = 14:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0056 0.00287 Inf -1.970 0.1200
control - post_w2 0.0035 0.00329 Inf 1.050 0.5440
post_w1 - post_w2 0.0091 0.00329 Inf 2.770 0.0150
syllable = 15:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0001 0.00287 Inf 0.040 0.9990
control - post_w2 -0.0056 0.00329 Inf -1.700 0.2060
post_w1 - post_w2 -0.0057 0.00329 Inf -1.740 0.1920
syllable = 16:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0117 0.00289 Inf -4.040 <.0001
control - post_w2 0.0040 0.00330 Inf 1.220 0.4440
post_w1 - post_w2 0.0157 0.00329 Inf 4.780 <.0001
syllable = 17:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0021 0.00287 Inf 0.740 0.7420
control - post_w2 0.0117 0.00329 Inf 3.550 0.0010
post_w1 - post_w2 0.0096 0.00329 Inf 2.910 0.0100
syllable = 18:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0036 0.00287 Inf 1.260 0.4170
control - post_w2 -0.0012 0.00329 Inf -0.370 0.9260
post_w1 - post_w2 -0.0048 0.00329 Inf -1.480 0.3030
syllable = 19:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0018 0.00287 Inf 0.630 0.8040
control - post_w2 -0.0115 0.00329 Inf -3.500 0.0010
post_w1 - post_w2 -0.0133 0.00329 Inf -4.050 <.0001
syllable = 20:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0071 0.00290 Inf 2.450 0.0380
control - post_w2 -0.0073 0.00330 Inf -2.210 0.0700
post_w1 - post_w2 -0.0144 0.00330 Inf -4.360 <.0001
syllable = 21:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0032 0.00292 Inf -1.100 0.5160
control - post_w2 -0.0068 0.00336 Inf -2.040 0.1030
post_w1 - post_w2 -0.0036 0.00335 Inf -1.090 0.5220
syllable = 22:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0076 0.00289 Inf -2.640 0.0230
control - post_w2 -0.0017 0.00333 Inf -0.500 0.8720
post_w1 - post_w2 0.0060 0.00335 Inf 1.780 0.1760
syllable = 23:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0054 0.00291 Inf 1.860 0.1510
control - post_w2 -0.0021 0.00333 Inf -0.630 0.8010
post_w1 - post_w2 -0.0075 0.00336 Inf -2.230 0.0650
syllable = 24:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0013 0.00291 Inf -0.460 0.8910
control - post_w2 0.0000 0.00332 Inf -0.010 1.0000
post_w1 - post_w2 0.0013 0.00329 Inf 0.390 0.9190
syllable = 25:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0103 0.00291 Inf 3.560 0.0010
control - post_w2 0.0123 0.00336 Inf 3.650 0.0010
post_w1 - post_w2 0.0019 0.00333 Inf 0.580 0.8330
syllable = 26:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0072 0.00308 Inf 2.350 0.0490
control - post_w2 0.0016 0.00373 Inf 0.440 0.8990
post_w1 - post_w2 -0.0056 0.00366 Inf -1.530 0.2770
syllable = 27:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0058 0.00293 Inf -1.980 0.1180
control - post_w2 -0.0016 0.00353 Inf -0.440 0.8970
post_w1 - post_w2 0.0042 0.00348 Inf 1.210 0.4460
syllable = 28:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0049 0.00289 Inf 1.680 0.2120
control - post_w2 0.0002 0.00335 Inf 0.070 0.9970
post_w1 - post_w2 -0.0046 0.00333 Inf -1.390 0.3480
syllable = 29:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0054 0.00303 Inf -1.790 0.1730
control - post_w2 -0.0046 0.00366 Inf -1.260 0.4180
post_w1 - post_w2 0.0008 0.00369 Inf 0.220 0.9730
syllable = 30:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0000 0.00291 Inf -0.010 1.0000
control - post_w2 -0.0050 0.00332 Inf -1.510 0.2840
post_w1 - post_w2 -0.0050 0.00329 Inf -1.520 0.2820
syllable = 31:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0023 0.00287 Inf -0.790 0.7070
control - post_w2 -0.0008 0.00329 Inf -0.250 0.9650
post_w1 - post_w2 0.0014 0.00329 Inf 0.440 0.8990
syllable = 32:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0004 0.00287 Inf 0.130 0.9910
control - post_w2 -0.0006 0.00333 Inf -0.170 0.9850
post_w1 - post_w2 -0.0009 0.00333 Inf -0.280 0.9590
syllable = 33:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0029 0.00287 Inf 1.020 0.5650
control - post_w2 0.0001 0.00329 Inf 0.020 1.0000
post_w1 - post_w2 -0.0029 0.00329 Inf -0.870 0.6580
syllable = 34:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0026 0.00301 Inf -0.870 0.6620
control - post_w2 -0.0005 0.00357 Inf -0.140 0.9890
post_w1 - post_w2 0.0021 0.00363 Inf 0.580 0.8330
syllable = 35:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0044 0.00305 Inf -1.450 0.3130
control - post_w2 0.0042 0.00378 Inf 1.120 0.5000
post_w1 - post_w2 0.0087 0.00373 Inf 2.330 0.0520
syllable = 36:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0010 0.00305 Inf -0.330 0.9420
control - post_w2 -0.0005 0.00361 Inf -0.140 0.9890
post_w1 - post_w2 0.0005 0.00363 Inf 0.140 0.9900
syllable = 37:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0001 0.00307 Inf -0.030 0.9990
control - post_w2 -0.0018 0.00349 Inf -0.500 0.8700
post_w1 - post_w2 -0.0017 0.00345 Inf -0.480 0.8800
syllable = 38:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0047 0.00328 Inf 1.430 0.3260
control - post_w2 0.0067 0.00443 Inf 1.520 0.2810
post_w1 - post_w2 0.0020 0.00451 Inf 0.450 0.8920
syllable = 39:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0010 0.00325 Inf 0.300 0.9520
control - post_w2 -0.0012 0.00340 Inf -0.350 0.9340
post_w1 - post_w2 -0.0022 0.00352 Inf -0.610 0.8130
syllable = 40:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0028 0.00346 Inf -0.810 0.6940
control - post_w2 -0.0011 0.00375 Inf -0.290 0.9540
post_w1 - post_w2 0.0017 0.00363 Inf 0.470 0.8840
syllable = 41:
contrast estimate SE df z.ratio p.value
control - post_w1 0.0010 0.00337 Inf 0.290 0.9540
control - post_w2 -0.0030 0.00420 Inf -0.720 0.7490
post_w1 - post_w2 -0.0040 0.00408 Inf -0.990 0.5860
syllable = 42:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0021 0.00353 Inf -0.610 0.8160
control - post_w2 -0.0009 0.00402 Inf -0.230 0.9720
post_w1 - post_w2 0.0012 0.00375 Inf 0.330 0.9430
syllable = 43:
contrast estimate SE df z.ratio p.value
control - post_w1 -0.0002 0.00320 Inf -0.070 0.9970
control - post_w2 0.0019 0.00358 Inf 0.530 0.8580
post_w1 - post_w2 0.0021 0.00346 Inf 0.610 0.8160
Degrees-of-freedom method: asymptotic
P value adjustment: tukey method for comparing a family of 3 estimates
#for ggplot below
syllable_labels_3ct <- c(
"0" = "0 (sniff_right)",
"1" = "1 (sniff_stationary)",
"2" = "2 (acceleration_arch_after)",
"3" = "3 (diagonal_left)",
"4" = "4 (sniff_left)",
"5" = "5 (turn_right_moderate)",
"6" = "6 (locomotion_brief)",
"7" = "7 (turn_left_moderate)",
"8" = "8 (locomotion_sniff)",
"9" = "9 (locomotion_head_turn)",
"10" = "10 (accelerate_brief)",
"11" = "11 (locomotion_arch_before)",
"12" = "12 (locomotion_arch_brief)",
"13" = "13 (stand-still_brief)",
"14" = "14 (locomotion_stop_sniff)",
"15" = "15 (locomotion_arch_left)",
"16" = "16 (rear_unsupported/interact_arch)",
"17" = "17 (rear_unsupported/supported)",
"18" = "18 (alongside_divider)",
"19" = "19 (locomotion_arch_long)",
"20" = "20 (turn_divider)",
"21" = "21 (rear_supported_right)",
"22" = "22 (rear_supported/groom/sniff_arch)",
"23" = "23 (turn_sharp_right)",
"24" = "24 (locomotion_steps)",
"25" = "25 (sniff_up_left)",
"26" = "26 (rear_supported_chamber)",
"27" = "27 (rear_unsupported/approach_divider)",
"28" = "28 (acceleration_arch_brief)",
"29" = "29 (rear_supported_left)",
"30" = "30 (locomotion_arch_angle_right)",
"31" = "31 (sniff_arch)",
"32" = "32 (approach_divider)",
"33" = "33 (mixed)",
"34" = "34 (interact_divider)",
"35" = "35 (interact_arch)",
"36" = "36 (climb/jump)",
"37" = "37 (locomotion_arch_left_angle)",
"38" = "38 (stand-still_long)",
"39" = "39 (sniff_corners_left)",
"40" = "40 (arch_halt)",
"41" = "41 (sniff_chamber_corner)",
"42" = "42 (turn_sharp_left)",
"43" = "43 (mixed)"
)
# start to order by control frequency
#extract results from the emmeans
emm_df_3ct <- as.data.frame(emm_3ct) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, asymp.LCL, asymp.UCL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_3ct
# Get syllables in descending order of emmean from the control group
syllable_order_3ct <- emm_df_3ct %>%
filter(group == "control") %>%
arrange(desc(emmean)) %>% #computed mean frequency sorted from most to least
pull(syllable) %>% # Extract just the ordered syllable names, this controls x-axis of plot
as.character()
# Reapply the factor with new levels
emm_df_3ct <- emm_df_3ct %>%
mutate(syllable = factor(syllable, levels = syllable_order_3ct))
emm_df_3ct
#this data will be used for plotting
# Apply the same syllable ordering as in emm_df
# Convert the pairwise results into a data frame using summary
pairwise_results_3ct <- summary(pairwise_3ct)
# Filter significant results (p-value < 0.05)
sig_results_3ct <- pairwise_results_3ct[pairwise_results_3ct$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_3ct <- sig_results_3ct %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
sig_syllables_3ct <- sig_syllables_3ct %>%
mutate(syllable = factor(syllable, levels = levels(emm_df_3ct$syllable)))
# Print sig_syllables to check
print(sig_syllables_3ct)
#check if factor ordering is same
levels(emm_df_3ct$syllable)
[1] "1" "0" "4" "3" "5" "2" "7" "9" "8" "13" "6" "10" "17" "14" "12" "15" "11" "25" "18" "16" "26"
[22] "20" "19" "23" "24" "28" "21" "22" "33" "38" "27" "29" "32" "30" "31" "41" "35" "34" "36" "39" "43" "37"
[43] "42" "40"
levels(sig_syllables_3ct$syllable)
[1] "1" "0" "4" "3" "5" "2" "7" "9" "8" "13" "6" "10" "17" "14" "12" "15" "11" "25" "18" "16" "26"
[22] "20" "19" "23" "24" "28" "21" "22" "33" "38" "27" "29" "32" "30" "31" "41" "35" "34" "36" "39" "43" "37"
[43] "42" "40"
# Create the plot
plot_3ct <- ggplot(emm_df_3ct, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
#geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_3ct) +
# Labels for axes and legend
labs(
x = "Syllables",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 18),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_3ct <- plot_3ct + geom_text(
data = sig_syllables_3ct,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "post_w1 - post_w2" ~ 0.24,
contrast == "control - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_3ct
#ggsave("3ct_graph(FINAL).png", plot = plot_3ct, width = 15, height = 6) #makes spaces visible
#geelm model OFT
#geelm model
#Generalized estimating equations Generalised Linear Model
#testing data with geeglm for non-normal data and repeated measures
#it doesn't model random effects, so it’s best when you're interested in average population trends rather than individual subject trajectories
#models populations average rather than individual differences like lmer with random intercepts.
#it clusters ID together
#HOWEVER, it is not ideal for for missing data
##FURTHERMORE EXPLANATION ON MISSING DATA. Since the mice are sacrificed because their symptoms get too severe, and those symptoms relate directly to the outcome you’re studying (severity of disease), the missingness depends on the unobserved outcome itself (because after sacrifice, you no longer get data).
#Thus, this model is not compatible.
#This is a classic example of Missing Not At Random (MNAR) — the missing data is linked to the very thing you're measuring (severity), which you can’t fully observe after sacrifice.
model_gee_oft <- geeglm(frequency ~ group * syllable, id = ID, data = df_oft, family = gaussian,corstr = "exchangeable") # Can be "independence", "ar1", "unstructured"
summary(model_gee_oft)
Call:
geeglm(formula = frequency ~ group * syllable, family = gaussian,
data = df_oft, id = ID, corstr = "exchangeable")
Coefficients:
Estimate Std.err Wald Pr(>|W|)
(Intercept) 0.15601 0.01166 179.01 < 2e-16 ***
grouppost_w1 0.02151 0.01841 1.36 0.24270
grouppost_w2 -0.01872 0.01467 1.63 0.20177
syllable1 -0.01760 0.02100 0.70 0.40194
syllable2 -0.05535 0.00884 39.21 3.8e-10 ***
syllable3 -0.09083 0.01157 61.59 4.2e-15 ***
syllable4 -0.10562 0.01417 55.56 9.1e-14 ***
syllable5 -0.10864 0.01055 105.99 < 2e-16 ***
syllable6 -0.13416 0.01450 85.56 < 2e-16 ***
syllable7 -0.11440 0.01378 68.88 < 2e-16 ***
syllable8 -0.12602 0.00897 197.36 < 2e-16 ***
syllable9 -0.10969 0.01199 83.76 < 2e-16 ***
syllable10 -0.14778 0.01212 148.80 < 2e-16 ***
syllable11 -0.11148 0.01509 54.57 1.5e-13 ***
syllable12 -0.14153 0.01250 128.29 < 2e-16 ***
syllable13 -0.13796 0.01343 105.55 < 2e-16 ***
syllable14 -0.13986 0.01336 109.60 < 2e-16 ***
syllable15 -0.14767 0.01215 147.83 < 2e-16 ***
syllable16 -0.14019 0.01124 155.64 < 2e-16 ***
syllable17 -0.14698 0.01349 118.73 < 2e-16 ***
syllable18 -0.14069 0.01364 106.31 < 2e-16 ***
syllable19 -0.15058 0.01124 179.45 < 2e-16 ***
syllable20 -0.13325 0.01477 81.42 < 2e-16 ***
syllable21 -0.13229 0.01452 83.07 < 2e-16 ***
syllable22 -0.14210 0.01100 167.00 < 2e-16 ***
syllable23 -0.14415 0.01340 115.73 < 2e-16 ***
syllable24 -0.14784 0.01120 174.19 < 2e-16 ***
syllable25 -0.14908 0.01216 150.21 < 2e-16 ***
syllable26 -0.14885 0.01202 153.24 < 2e-16 ***
syllable27 -0.15140 0.01142 175.81 < 2e-16 ***
syllable28 -0.14822 0.01245 141.64 < 2e-16 ***
grouppost_w1:syllable1 -0.01095 0.03509 0.10 0.75502
grouppost_w2:syllable1 0.02279 0.02581 0.78 0.37727
grouppost_w1:syllable2 -0.03385 0.01524 4.93 0.02632 *
grouppost_w2:syllable2 -0.03127 0.01282 5.95 0.01469 *
grouppost_w1:syllable3 -0.01601 0.01679 0.91 0.34035
grouppost_w2:syllable3 0.05035 0.01492 11.39 0.00074 ***
grouppost_w1:syllable4 -0.00879 0.01963 0.20 0.65440
grouppost_w2:syllable4 0.06689 0.01775 14.19 0.00016 ***
grouppost_w1:syllable5 -0.03146 0.01613 3.80 0.05113 .
grouppost_w2:syllable5 0.01689 0.01497 1.27 0.25932
grouppost_w1:syllable6 -0.01673 0.02346 0.51 0.47575
grouppost_w2:syllable6 0.04199 0.02027 4.29 0.03831 *
grouppost_w1:syllable7 -0.03748 0.01909 3.85 0.04962 *
grouppost_w2:syllable7 0.00526 0.01730 0.09 0.76130
grouppost_w1:syllable8 -0.01837 0.01512 1.48 0.22429
grouppost_w2:syllable8 0.01160 0.01246 0.87 0.35196
grouppost_w1:syllable9 -0.04496 0.01959 5.27 0.02171 *
grouppost_w2:syllable9 -0.01053 0.01640 0.41 0.52055
grouppost_w1:syllable10 -0.01172 0.01840 0.41 0.52422
grouppost_w2:syllable10 0.06603 0.01757 14.13 0.00017 ***
grouppost_w1:syllable11 -0.04693 0.02296 4.18 0.04097 *
grouppost_w2:syllable11 -0.01582 0.01834 0.74 0.38843
grouppost_w1:syllable12 -0.01087 0.02301 0.22 0.63664
grouppost_w2:syllable12 0.02705 0.01830 2.19 0.13930
grouppost_w1:syllable13 -0.02410 0.02085 1.34 0.24778
grouppost_w2:syllable13 0.02867 0.01725 2.76 0.09656 .
grouppost_w1:syllable14 -0.01576 0.02072 0.58 0.44694
grouppost_w2:syllable14 0.02605 0.01666 2.44 0.11793
grouppost_w1:syllable15 -0.01627 0.01875 0.75 0.38536
grouppost_w2:syllable15 0.03827 0.01629 5.52 0.01878 *
grouppost_w1:syllable16 -0.01958 0.01638 1.43 0.23188
grouppost_w2:syllable16 0.01452 0.01358 1.14 0.28490
grouppost_w1:syllable17 -0.01275 0.02190 0.34 0.56025
grouppost_w2:syllable17 0.02565 0.01813 2.00 0.15718
grouppost_w1:syllable18 -0.02353 0.02214 1.13 0.28797
grouppost_w2:syllable18 0.01847 0.01756 1.11 0.29267
grouppost_w1:syllable19 -0.01118 0.01786 0.39 0.53146
grouppost_w2:syllable19 0.03964 0.01498 7.00 0.00816 **
grouppost_w1:syllable20 -0.03629 0.02106 2.97 0.08484 .
grouppost_w2:syllable20 0.00139 0.01762 0.01 0.93717
grouppost_w1:syllable21 -0.03853 0.02092 3.39 0.06550 .
grouppost_w2:syllable21 -0.00287 0.01818 0.02 0.87470
grouppost_w1:syllable22 -0.02100 0.01746 1.45 0.22909
grouppost_w2:syllable22 0.00971 0.01410 0.47 0.49106
grouppost_w1:syllable23 -0.02067 0.01982 1.09 0.29689
grouppost_w2:syllable23 0.01366 0.01695 0.65 0.42011
grouppost_w1:syllable24 -0.01986 0.01776 1.25 0.26356
grouppost_w2:syllable24 0.01424 0.01425 1.00 0.31733
grouppost_w1:syllable25 -0.02079 0.01867 1.24 0.26544
grouppost_w2:syllable25 0.01742 0.01505 1.34 0.24723
grouppost_w1:syllable26 -0.02026 0.01895 1.14 0.28496
grouppost_w2:syllable26 0.01463 0.01472 0.99 0.32030
grouppost_w1:syllable27 -0.01924 0.02045 0.88 0.34686
grouppost_w2:syllable27 0.01834 0.01395 1.73 0.18865
grouppost_w1:syllable28 -0.02540 0.01929 1.73 0.18779
grouppost_w2:syllable28 0.01529 0.01532 1.00 0.31840
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation structure = exchangeable
Estimated Scale Parameters:
Link = identity
Estimated Correlation Parameters:
Number of clusters: 37 Maximum cluster size: 29
gee_emm_oft <- emmeans(model_gee_oft, ~ group * syllable)
gee_emm_oft
group syllable emmean SE df lower.CL upper.CL
control 0 0.1560 0.01170 890 0.1331 0.1789
post_w1 0 0.1775 0.01420 890 0.1495 0.2055
post_w2 0 0.1373 0.00890 890 0.1198 0.1547
control 1 0.1384 0.01080 890 0.1171 0.1597
post_w1 1 0.1490 0.01550 890 0.1185 0.1794
post_w2 1 0.1425 0.00865 890 0.1255 0.1594
control 2 0.1007 0.01140 890 0.0783 0.1230
post_w1 2 0.0883 0.00975 890 0.0692 0.1075
post_w2 2 0.0507 0.00914 890 0.0327 0.0686
control 3 0.0652 0.00543 890 0.0545 0.0758
post_w1 3 0.0707 0.00772 890 0.0555 0.0858
post_w2 3 0.0968 0.00865 890 0.0798 0.1138
control 4 0.0504 0.00591 890 0.0388 0.0620
post_w1 4 0.0631 0.00497 890 0.0534 0.0729
post_w2 4 0.0986 0.00468 890 0.0894 0.1077
control 5 0.0474 0.00471 890 0.0381 0.0566
post_w1 5 0.0374 0.00528 890 0.0271 0.0478
post_w2 5 0.0455 0.00724 890 0.0313 0.0597
control 6 0.0218 0.00355 890 0.0149 0.0288
post_w1 6 0.0266 0.00546 890 0.0159 0.0373
post_w2 6 0.0451 0.00606 890 0.0332 0.0570
control 7 0.0416 0.00511 890 0.0316 0.0516
post_w1 7 0.0256 0.00446 890 0.0169 0.0344
post_w2 7 0.0281 0.00585 890 0.0167 0.0396
control 8 0.0300 0.00463 890 0.0209 0.0391
post_w1 8 0.0331 0.00411 890 0.0251 0.0412
post_w2 8 0.0229 0.00344 890 0.0161 0.0296
control 9 0.0463 0.00370 890 0.0391 0.0536
post_w1 9 0.0229 0.00262 890 0.0177 0.0280
post_w2 9 0.0171 0.00446 890 0.0083 0.0258
control 10 0.0082 0.00155 890 0.0052 0.0113
post_w1 10 0.0180 0.00369 890 0.0108 0.0253
post_w2 10 0.0555 0.00624 890 0.0433 0.0678
control 11 0.0445 0.00499 890 0.0347 0.0543
post_w1 11 0.0191 0.00596 890 0.0074 0.0308
post_w2 11 0.0100 0.00359 890 0.0029 0.0170
control 12 0.0145 0.00255 890 0.0095 0.0195
post_w1 12 0.0251 0.00751 890 0.0104 0.0398
post_w2 12 0.0228 0.00535 890 0.0123 0.0333
control 13 0.0180 0.00295 890 0.0123 0.0238
post_w1 13 0.0155 0.00233 890 0.0109 0.0200
post_w2 13 0.0280 0.00363 890 0.0209 0.0351
control 14 0.0161 0.00257 890 0.0111 0.0212
post_w1 14 0.0219 0.00318 890 0.0157 0.0282
post_w2 14 0.0235 0.00339 890 0.0168 0.0301
control 15 0.0083 0.00205 890 0.0043 0.0124
post_w1 15 0.0136 0.00193 890 0.0098 0.0174
post_w2 15 0.0279 0.00474 890 0.0186 0.0372
control 16 0.0158 0.00208 890 0.0117 0.0199
post_w1 16 0.0177 0.00374 890 0.0104 0.0251
post_w2 16 0.0116 0.00264 890 0.0064 0.0168
control 17 0.0090 0.00243 890 0.0043 0.0138
post_w1 17 0.0178 0.00434 890 0.0093 0.0263
post_w2 17 0.0160 0.00454 890 0.0071 0.0249
control 18 0.0153 0.00383 890 0.0078 0.0228
post_w1 18 0.0133 0.00439 890 0.0047 0.0219
post_w2 18 0.0151 0.00355 890 0.0081 0.0220
control 19 0.0054 0.00224 890 0.0010 0.0098
post_w1 19 0.0158 0.00435 890 0.0072 0.0243
post_w2 19 0.0263 0.00725 890 0.0121 0.0406
control 20 0.0228 0.00438 890 0.0142 0.0314
post_w1 20 0.0080 0.00215 890 0.0038 0.0122
post_w2 20 0.0054 0.00257 890 0.0004 0.0105
control 21 0.0237 0.00446 890 0.0150 0.0325
post_w1 21 0.0067 0.00235 890 0.0021 0.0113
post_w2 21 0.0021 0.00465 890 -0.0070 0.0112
control 22 0.0139 0.00350 890 0.0070 0.0208
post_w1 22 0.0144 0.00262 890 0.0093 0.0196
post_w2 22 0.0049 0.00106 890 0.0028 0.0070
control 23 0.0119 0.00319 890 0.0056 0.0181
post_w1 23 0.0127 0.00272 890 0.0074 0.0180
post_w2 23 0.0068 0.00217 890 0.0025 0.0111
control 24 0.0082 0.00222 890 0.0038 0.0125
post_w1 24 0.0098 0.00297 890 0.0040 0.0157
post_w2 24 0.0037 0.00211 890 -0.0005 0.0078
control 25 0.0069 0.00182 890 0.0033 0.0105
post_w1 25 0.0077 0.00220 890 0.0033 0.0120
post_w2 25 0.0056 0.00102 890 0.0036 0.0076
control 26 0.0072 0.00204 890 0.0032 0.0112
post_w1 26 0.0084 0.00163 890 0.0052 0.0116
post_w2 26 0.0031 0.00102 890 0.0011 0.0051
control 27 0.0046 0.00268 890 -0.0007 0.0099
post_w1 27 0.0069 0.00412 890 -0.0012 0.0150
post_w2 27 0.0042 0.00278 890 -0.0012 0.0097
control 28 0.0078 0.00236 890 0.0032 0.0124
post_w1 28 0.0039 0.00215 890 -0.0003 0.0081
post_w2 28 0.0044 0.00165 890 0.0011 0.0076
Covariance estimate used: vbeta
Confidence level used: 0.95
gee_contrast_oft <- contrast(gee_emm_oft, method = "pairwise", by = "syllable", adjust = "tukey")
gee_contrast_oft
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0215 0.01840 890 -1.170 0.4730
control - post_w2 0.0187 0.01470 890 1.280 0.4090
post_w1 - post_w2 0.0402 0.01680 890 2.390 0.0440
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0106 0.01890 890 -0.560 0.8420
control - post_w2 -0.0041 0.01390 890 -0.290 0.9540
post_w1 - post_w2 0.0065 0.01780 890 0.370 0.9290
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0123 0.01500 890 0.820 0.6880
control - post_w2 0.0500 0.01460 890 3.430 0.0020
post_w1 - post_w2 0.0377 0.01340 890 2.820 0.0140
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0055 0.00944 890 -0.580 0.8290
control - post_w2 -0.0316 0.01020 890 -3.100 0.0060
post_w1 - post_w2 -0.0261 0.01160 890 -2.250 0.0630
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0127 0.00772 890 -1.650 0.2260
control - post_w2 -0.0482 0.00754 890 -6.390 <.0001
post_w1 - post_w2 -0.0354 0.00682 890 -5.190 <.0001
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0099 0.00707 890 1.410 0.3380
control - post_w2 0.0018 0.00864 890 0.210 0.9750
post_w1 - post_w2 -0.0081 0.00896 890 -0.910 0.6370
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0048 0.00651 890 -0.730 0.7430
control - post_w2 -0.0233 0.00702 890 -3.310 0.0030
post_w1 - post_w2 -0.0185 0.00816 890 -2.270 0.0610
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0160 0.00679 890 2.350 0.0490
control - post_w2 0.0135 0.00777 890 1.730 0.1930
post_w1 - post_w2 -0.0025 0.00735 890 -0.340 0.9380
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0031 0.00619 890 -0.510 0.8680
control - post_w2 0.0071 0.00576 890 1.240 0.4320
post_w1 - post_w2 0.0103 0.00536 890 1.920 0.1340
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0234 0.00453 890 5.170 <.0001
control - post_w2 0.0293 0.00580 890 5.050 <.0001
post_w1 - post_w2 0.0058 0.00518 890 1.120 0.5010
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0098 0.00400 890 -2.450 0.0390
control - post_w2 -0.0473 0.00643 890 -7.360 <.0001
post_w1 - post_w2 -0.0375 0.00724 890 -5.180 <.0001
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0254 0.00778 890 3.270 0.0030
control - post_w2 0.0345 0.00615 890 5.620 <.0001
post_w1 - post_w2 0.0091 0.00696 890 1.310 0.3890
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0106 0.00793 890 -1.340 0.3720
control - post_w2 -0.0083 0.00593 890 -1.400 0.3390
post_w1 - post_w2 0.0023 0.00922 890 0.250 0.9660
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0026 0.00376 890 0.690 0.7700
control - post_w2 -0.0099 0.00468 890 -2.130 0.0850
post_w1 - post_w2 -0.0125 0.00431 890 -2.910 0.0100
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0058 0.00409 890 -1.410 0.3380
control - post_w2 -0.0073 0.00425 890 -1.720 0.1970
post_w1 - post_w2 -0.0016 0.00465 890 -0.340 0.9390
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0052 0.00282 890 -1.860 0.1510
control - post_w2 -0.0195 0.00516 890 -3.790 <.0001
post_w1 - post_w2 -0.0143 0.00511 890 -2.800 0.0150
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0019 0.00428 890 -0.450 0.8940
control - post_w2 0.0042 0.00336 890 1.250 0.4240
post_w1 - post_w2 0.0061 0.00458 890 1.340 0.3740
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0088 0.00497 890 -1.760 0.1830
control - post_w2 -0.0069 0.00515 890 -1.350 0.3700
post_w1 - post_w2 0.0018 0.00627 890 0.290 0.9540
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0020 0.00583 890 0.350 0.9360
control - post_w2 0.0002 0.00522 890 0.050 0.9990
post_w1 - post_w2 -0.0018 0.00564 890 -0.310 0.9470
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0103 0.00489 890 -2.110 0.0880
control - post_w2 -0.0209 0.00759 890 -2.750 0.0160
post_w1 - post_w2 -0.0106 0.00846 890 -1.250 0.4240
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0148 0.00488 890 3.030 0.0070
control - post_w2 0.0173 0.00507 890 3.420 0.0020
post_w1 - post_w2 0.0026 0.00335 890 0.760 0.7260
syllable = 21:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0170 0.00504 890 3.380 0.0020
control - post_w2 0.0216 0.00644 890 3.350 0.0020
post_w1 - post_w2 0.0046 0.00520 890 0.880 0.6540
syllable = 22:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0005 0.00437 890 -0.120 0.9930
control - post_w2 0.0090 0.00366 890 2.470 0.0370
post_w1 - post_w2 0.0095 0.00283 890 3.370 0.0020
syllable = 23:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0008 0.00419 890 -0.200 0.9780
control - post_w2 0.0051 0.00386 890 1.310 0.3890
post_w1 - post_w2 0.0059 0.00348 890 1.700 0.2070
syllable = 24:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0017 0.00371 890 -0.450 0.8960
control - post_w2 0.0045 0.00306 890 1.460 0.3090
post_w1 - post_w2 0.0061 0.00364 890 1.680 0.2120
syllable = 25:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0007 0.00286 890 -0.250 0.9650
control - post_w2 0.0013 0.00209 890 0.630 0.8060
post_w1 - post_w2 0.0020 0.00242 890 0.840 0.6790
syllable = 26:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0012 0.00261 890 -0.480 0.8810
control - post_w2 0.0041 0.00228 890 1.800 0.1710
post_w1 - post_w2 0.0053 0.00192 890 2.790 0.0150
syllable = 27:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0023 0.00492 890 -0.460 0.8890
control - post_w2 0.0004 0.00387 890 0.100 0.9940
post_w1 - post_w2 0.0027 0.00497 890 0.530 0.8540
syllable = 28:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0039 0.00320 890 1.220 0.4430
control - post_w2 0.0034 0.00288 890 1.190 0.4580
post_w1 - post_w2 -0.0005 0.00271 890 -0.170 0.9850
P value adjustment: tukey method for comparing a family of 3 estimates
#this data will be used for plotting
# Filter significant results (p-value < 0.05)
gee_contrast_oft_tuk <- gee_contrast_oft_tuk[gee_contrast_oft_tuk$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_oft_gee <- gee_contrast_oft_tuk %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
#make factor levels same for a-axis
sig_syllables_oft_gee <- sig_syllables_oft_gee %>%
mutate(syllable = factor(syllable, levels = syllable_order_oft_gee))
# Print sig_syllables to check
print(sig_syllables_oft_gee)
# start to order by control frequency
#turn into dataframe
#extract results from the emmeans
emm_df_oft_gee <- as.data.frame(gee_emm_oft) %>%
# Select the relevant columns
select(group, syllable, emmean, SE, df, lower.CL, upper.CL) %>%
mutate(
syllable = as.factor(syllable), # Ensure syllable is a factor
group = factor(group, levels = c("control", "post_w1", "post_w2")) # Factor level for plotting
)
# View the resulting formatted data
emm_df_oft_gee
# Get syllables in descending order of emmean from the control group
syllable_order_oft_gee <- emm_df_oft_gee %>%
filter(group == "control") %>%
arrange(desc(emmean)) %>% #computed mean frequency sorted from most to least
pull(syllable) %>% # Extract just the ordered syllable names, this controls x-axis of plot
as.character()
# Reapply the factor with new levels
emm_df_oft_gee <- emm_df_oft_gee %>%
mutate(syllable = factor(syllable, levels = syllable_order_oft_gee))
emm_df_oft_gee
NA
#check if factor ordering is same
levels(emm_df_oft_gee$syllable)
[1] "0" "1" "2" "3" "4" "5" "9" "11" "7" "8" "21" "20" "6" "13" "14" "16" "18" "12" "22" "23" "17"
[22] "15" "10" "24" "28" "26" "25" "19" "27"
levels(sig_syllables_oft_gee$syllable)
[1] "0" "1" "2" "3" "4" "5" "9" "11" "7" "8" "21" "20" "6" "13" "14" "16" "18" "12" "22" "23" "17"
[22] "15" "10" "24" "28" "26" "25" "19" "27"
# Create the plot
plot_oft_gee <- ggplot(emm_df_oft_gee, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
# geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_oft) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_oft_gee <- plot_oft_gee + geom_text(
data = sig_syllables_oft_gee,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "post_w1 - post_w2" ~ 0.24,
contrast == "control - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_oft_gee
#ggsave("oft_graph(SE)_gee.png", plot = plot_oft_gee, width = 10, height = 6) #makes spaces visible
##assumptions_OFT
# Extract Pearson residuals
residuals_gee <- residuals(model_gee_oft, type = "pearson")
# Plot residuals vs fitted values
plot(fitted(model_gee_oft), residuals_gee)
abline(h = 0, col = "red")
#geelm model NOR
#geelm model EPM
#geelm model 3CT
model_gee_3ct <- geeglm(frequency ~ group * syllable, id = ID, data = df_3ct, family = gaussian,corstr = "exchangeable") # Can be "independence", "ar1", "unstructured"
summary(model_gee_3ct)
Call:
geeglm(formula = frequency ~ group * syllable, family = gaussian,
data = df_3ct, id = ID, corstr = "exchangeable")
Coefficients:
Estimate Std.err Wald Pr(>|W|)
(Intercept) 8.37e-02 6.71e-03 155.49 < 2e-16 ***
grouppost_w1 -1.99e-02 8.29e-03 5.78 0.01620 *
grouppost_w2 -3.97e-03 1.14e-02 0.12 0.72812
syllable1 5.25e-03 3.67e-03 2.05 0.15210
syllable2 -4.86e-02 7.53e-03 41.67 1.1e-10 ***
syllable3 -4.35e-02 5.04e-03 74.46 < 2e-16 ***
syllable4 -3.76e-02 5.18e-03 52.63 4.0e-13 ***
syllable5 -4.69e-02 8.11e-03 33.45 7.3e-09 ***
syllable6 -5.47e-02 9.96e-03 30.12 4.1e-08 ***
syllable7 -4.92e-02 8.34e-03 34.77 3.7e-09 ***
syllable8 -5.17e-02 8.45e-03 37.42 9.5e-10 ***
syllable9 -5.09e-02 6.82e-03 55.66 8.6e-14 ***
syllable10 -5.47e-02 8.14e-03 45.18 1.8e-11 ***
syllable11 -6.09e-02 7.41e-03 67.61 2.2e-16 ***
syllable12 -5.91e-02 7.33e-03 65.04 7.8e-16 ***
syllable13 -5.29e-02 7.72e-03 46.96 7.2e-12 ***
syllable14 -5.82e-02 7.40e-03 61.77 3.9e-15 ***
syllable15 -6.00e-02 7.42e-03 65.37 6.7e-16 ***
syllable16 -6.28e-02 7.23e-03 75.60 < 2e-16 ***
syllable17 -5.75e-02 7.63e-03 56.75 5.0e-14 ***
syllable18 -6.17e-02 7.07e-03 76.07 < 2e-16 ***
syllable19 -6.62e-02 5.93e-03 124.49 < 2e-16 ***
syllable20 -6.46e-02 5.86e-03 121.70 < 2e-16 ***
syllable21 -7.15e-02 7.76e-03 84.75 < 2e-16 ***
syllable22 -7.16e-02 6.89e-03 107.95 < 2e-16 ***
syllable23 -6.70e-02 6.08e-03 121.47 < 2e-16 ***
syllable24 -6.90e-02 7.75e-03 79.24 < 2e-16 ***
syllable25 -6.11e-02 7.49e-03 66.53 3.3e-16 ***
syllable26 -6.38e-02 8.49e-03 56.42 5.9e-14 ***
syllable27 -7.22e-02 7.92e-03 83.25 < 2e-16 ***
syllable28 -6.93e-02 6.84e-03 102.71 < 2e-16 ***
syllable29 -7.25e-02 7.57e-03 91.74 < 2e-16 ***
syllable30 -7.29e-02 6.57e-03 123.34 < 2e-16 ***
syllable31 -7.29e-02 6.77e-03 115.83 < 2e-16 ***
syllable32 -7.27e-02 7.11e-03 104.36 < 2e-16 ***
syllable33 -7.19e-02 7.10e-03 102.45 < 2e-16 ***
syllable34 -7.61e-02 6.98e-03 119.03 < 2e-16 ***
syllable35 -7.56e-02 6.94e-03 118.56 < 2e-16 ***
syllable36 -7.61e-02 6.94e-03 120.17 < 2e-16 ***
syllable37 -7.75e-02 6.52e-03 141.20 < 2e-16 ***
syllable38 -7.20e-02 6.58e-03 119.95 < 2e-16 ***
syllable39 -7.71e-02 6.26e-03 151.51 < 2e-16 ***
syllable40 -7.78e-02 6.72e-03 134.13 < 2e-16 ***
syllable41 -7.53e-02 6.01e-03 156.96 < 2e-16 ***
syllable42 -7.75e-02 6.55e-03 140.14 < 2e-16 ***
syllable43 -7.73e-02 6.62e-03 136.32 < 2e-16 ***
grouppost_w1:syllable1 -2.24e-03 4.52e-03 0.25 0.61987
grouppost_w2:syllable1 -3.36e-02 8.69e-03 14.98 0.00011 ***
grouppost_w1:syllable2 2.70e-02 1.00e-02 7.23 0.00717 **
grouppost_w2:syllable2 1.38e-02 1.43e-02 0.93 0.33407
grouppost_w1:syllable3 8.12e-03 6.28e-03 1.67 0.19646
grouppost_w2:syllable3 1.47e-02 9.92e-03 2.19 0.13887
grouppost_w1:syllable4 8.62e-03 6.39e-03 1.82 0.17770
grouppost_w2:syllable4 -7.19e-03 9.73e-03 0.55 0.45984
grouppost_w1:syllable5 1.99e-02 1.03e-02 3.74 0.05323 .
grouppost_w2:syllable5 8.64e-03 1.29e-02 0.45 0.50274
grouppost_w1:syllable6 4.05e-02 1.40e-02 8.35 0.00386 **
grouppost_w2:syllable6 1.08e-02 1.81e-02 0.36 0.54817
grouppost_w1:syllable7 2.28e-02 1.05e-02 4.69 0.03030 *
grouppost_w2:syllable7 1.05e-02 1.35e-02 0.60 0.43703
grouppost_w1:syllable8 3.25e-02 1.06e-02 9.40 0.00217 **
grouppost_w2:syllable8 -2.46e-03 1.40e-02 0.03 0.86068
grouppost_w1:syllable9 2.20e-02 7.91e-03 7.73 0.00543 **
grouppost_w2:syllable9 7.85e-03 1.04e-02 0.57 0.44919
grouppost_w1:syllable10 1.38e-02 9.39e-03 2.14 0.14317
grouppost_w2:syllable10 1.19e-02 1.53e-02 0.61 0.43480
grouppost_w1:syllable11 2.63e-02 9.81e-03 7.20 0.00728 **
grouppost_w2:syllable11 1.77e-02 1.40e-02 1.61 0.20446
grouppost_w1:syllable12 2.13e-02 8.76e-03 5.91 0.01506 *
grouppost_w2:syllable12 1.75e-02 1.32e-02 1.75 0.18609
grouppost_w1:syllable13 2.24e-02 9.67e-03 5.39 0.02030 *
grouppost_w2:syllable13 -1.13e-02 1.29e-02 0.76 0.38240
grouppost_w1:syllable14 2.56e-02 9.12e-03 7.85 0.00507 **
grouppost_w2:syllable14 5.06e-04 1.32e-02 0.00 0.96940
grouppost_w1:syllable15 1.98e-02 9.06e-03 4.77 0.02890 *
grouppost_w2:syllable15 9.54e-03 1.36e-02 0.49 0.48252
grouppost_w1:syllable16 3.16e-02 9.34e-03 11.44 0.00072 ***
grouppost_w2:syllable16 -5.57e-05 1.10e-02 0.00 0.99595
grouppost_w1:syllable17 1.78e-02 9.47e-03 3.54 0.06002 .
grouppost_w2:syllable17 -7.72e-03 1.27e-02 0.37 0.54465
grouppost_w1:syllable18 1.63e-02 8.49e-03 3.68 0.05496 .
grouppost_w2:syllable18 5.19e-03 1.04e-02 0.25 0.61773
grouppost_w1:syllable19 1.81e-02 7.19e-03 6.35 0.01171 *
grouppost_w2:syllable19 1.55e-02 1.10e-02 1.97 0.16070
grouppost_w1:syllable20 1.28e-02 7.16e-03 3.20 0.07344 .
grouppost_w2:syllable20 1.12e-02 1.04e-02 1.17 0.27860
grouppost_w1:syllable21 2.31e-02 9.99e-03 5.36 0.02066 *
grouppost_w2:syllable21 1.08e-02 1.45e-02 0.55 0.45704
grouppost_w1:syllable22 2.75e-02 8.64e-03 10.16 0.00143 **
grouppost_w2:syllable22 5.62e-03 1.06e-02 0.28 0.59577
grouppost_w1:syllable23 1.45e-02 7.45e-03 3.79 0.05145 .
grouppost_w2:syllable23 6.07e-03 1.16e-02 0.27 0.60012
grouppost_w1:syllable24 2.12e-02 9.27e-03 5.26 0.02186 *
grouppost_w2:syllable24 4.00e-03 1.25e-02 0.10 0.74956
grouppost_w1:syllable25 9.57e-03 9.03e-03 1.12 0.28927
grouppost_w2:syllable25 -8.30e-03 1.09e-02 0.58 0.44782
grouppost_w1:syllable26 1.27e-02 1.05e-02 1.45 0.22794
grouppost_w2:syllable26 2.35e-03 1.42e-02 0.03 0.86896
grouppost_w1:syllable27 2.57e-02 9.95e-03 6.67 0.00981 **
grouppost_w2:syllable27 5.55e-03 1.26e-02 0.19 0.66028
grouppost_w1:syllable28 1.51e-02 8.55e-03 3.11 0.07793 .
grouppost_w2:syllable28 3.73e-03 1.27e-02 0.09 0.76925
grouppost_w1:syllable29 2.53e-02 9.61e-03 6.95 0.00836 **
grouppost_w2:syllable29 8.59e-03 1.30e-02 0.44 0.50935
grouppost_w1:syllable30 2.00e-02 8.21e-03 5.92 0.01501 *
grouppost_w2:syllable30 8.99e-03 1.17e-02 0.59 0.44067
grouppost_w1:syllable31 2.22e-02 8.68e-03 6.54 0.01052 *
grouppost_w2:syllable31 4.79e-03 1.18e-02 0.17 0.68356
grouppost_w1:syllable32 1.96e-02 8.52e-03 5.27 0.02165 *
grouppost_w2:syllable32 4.52e-03 1.20e-02 0.14 0.70637
grouppost_w1:syllable33 1.70e-02 8.87e-03 3.67 0.05529 .
grouppost_w2:syllable33 3.90e-03 1.19e-02 0.11 0.74300
grouppost_w1:syllable34 2.25e-02 8.59e-03 6.88 0.00873 **
grouppost_w2:syllable34 4.48e-03 1.12e-02 0.16 0.68890
grouppost_w1:syllable35 2.44e-02 8.72e-03 7.79 0.00525 **
grouppost_w2:syllable35 -2.93e-04 1.16e-02 0.00 0.97977
grouppost_w1:syllable36 2.09e-02 8.77e-03 5.70 0.01701 *
grouppost_w2:syllable36 4.48e-03 1.22e-02 0.13 0.71452
grouppost_w1:syllable37 2.00e-02 8.00e-03 6.25 0.01240 *
grouppost_w2:syllable37 5.71e-03 1.06e-02 0.29 0.59129
grouppost_w1:syllable38 1.52e-02 8.36e-03 3.33 0.06817 .
grouppost_w2:syllable38 -2.74e-03 1.57e-02 0.03 0.86171
grouppost_w1:syllable39 1.89e-02 7.95e-03 5.68 0.01720 *
grouppost_w2:syllable39 5.16e-03 1.09e-02 0.22 0.63605
grouppost_w1:syllable40 2.27e-02 8.38e-03 7.37 0.00664 **
grouppost_w2:syllable40 5.07e-03 1.13e-02 0.20 0.65255
grouppost_w1:syllable41 1.89e-02 7.66e-03 6.11 0.01344 *
grouppost_w2:syllable41 7.01e-03 8.62e-03 0.66 0.41613
grouppost_w1:syllable42 2.20e-02 8.53e-03 6.67 0.00979 **
grouppost_w2:syllable42 4.89e-03 1.17e-02 0.17 0.67653
grouppost_w1:syllable43 2.01e-02 8.38e-03 5.78 0.01625 *
grouppost_w2:syllable43 2.07e-03 1.12e-02 0.03 0.85407
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation structure = exchangeable
Estimated Scale Parameters:
Link = identity
Estimated Correlation Parameters:
Number of clusters: 47 Maximum cluster size: 131
gee_emm_3ct <- emmeans(model_gee_3ct, ~ group * syllable)
gee_emm_3ct
group syllable emmean SE df lower.CL upper.CL
control 0 0.0837 0.00671 4087 0.0705 0.0968
post_w1 0 0.0637 0.00486 4087 0.0542 0.0733
post_w2 0 0.0797 0.00923 4087 0.0616 0.0978
control 1 0.0889 0.00882 4087 0.0716 0.1062
post_w1 1 0.0667 0.00565 4087 0.0557 0.0778
post_w2 1 0.0513 0.00892 4087 0.0338 0.0688
control 2 0.0350 0.00189 4087 0.0313 0.0387
post_w1 2 0.0421 0.00209 4087 0.0380 0.0462
post_w2 2 0.0448 0.00430 4087 0.0364 0.0533
control 3 0.0402 0.00322 4087 0.0339 0.0465
post_w1 3 0.0284 0.00319 4087 0.0221 0.0346
post_w2 3 0.0509 0.00712 4087 0.0369 0.0648
control 4 0.0461 0.00313 4087 0.0400 0.0522
post_w1 4 0.0348 0.00208 4087 0.0307 0.0389
post_w2 4 0.0349 0.00255 4087 0.0299 0.0399
control 5 0.0368 0.00287 4087 0.0311 0.0424
post_w1 5 0.0367 0.00270 4087 0.0314 0.0420
post_w2 5 0.0414 0.00256 4087 0.0364 0.0465
control 6 0.0290 0.00379 4087 0.0216 0.0364
post_w1 6 0.0496 0.00542 4087 0.0389 0.0602
post_w2 6 0.0359 0.00782 4087 0.0205 0.0512
control 7 0.0345 0.00321 4087 0.0282 0.0408
post_w1 7 0.0374 0.00287 4087 0.0317 0.0430
post_w2 7 0.0410 0.00388 4087 0.0334 0.0486
control 8 0.0320 0.00270 4087 0.0267 0.0373
post_w1 8 0.0446 0.00252 4087 0.0396 0.0495
post_w2 8 0.0256 0.00410 4087 0.0175 0.0336
control 9 0.0328 0.00247 4087 0.0280 0.0376
post_w1 9 0.0349 0.00404 4087 0.0269 0.0428
post_w2 9 0.0367 0.00268 4087 0.0314 0.0419
control 10 0.0289 0.00300 4087 0.0230 0.0348
post_w1 10 0.0227 0.00248 4087 0.0179 0.0276
post_w2 10 0.0369 0.00631 4087 0.0245 0.0493
control 11 0.0227 0.00146 4087 0.0199 0.0256
post_w1 11 0.0291 0.00219 4087 0.0248 0.0334
post_w2 11 0.0365 0.00341 4087 0.0298 0.0432
control 12 0.0245 0.00183 4087 0.0209 0.0281
post_w1 12 0.0259 0.00130 4087 0.0233 0.0284
post_w2 12 0.0380 0.00365 4087 0.0309 0.0452
control 13 0.0307 0.00220 4087 0.0264 0.0351
post_w1 13 0.0333 0.00186 4087 0.0296 0.0369
post_w2 13 0.0155 0.00350 4087 0.0086 0.0224
control 14 0.0255 0.00201 4087 0.0215 0.0294
post_w1 14 0.0311 0.00303 4087 0.0252 0.0371
post_w2 14 0.0220 0.00317 4087 0.0158 0.0282
control 15 0.0237 0.00160 4087 0.0205 0.0268
post_w1 15 0.0235 0.00126 4087 0.0211 0.0260
post_w2 15 0.0292 0.00342 4087 0.0225 0.0359
control 16 0.0208 0.00164 4087 0.0176 0.0240
post_w1 16 0.0325 0.00290 4087 0.0268 0.0382
post_w2 16 0.0168 0.00217 4087 0.0126 0.0210
control 17 0.0262 0.00163 4087 0.0230 0.0294
post_w1 17 0.0241 0.00182 4087 0.0205 0.0276
post_w2 17 0.0145 0.00176 4087 0.0110 0.0179
control 18 0.0220 0.00126 4087 0.0195 0.0245
post_w1 18 0.0184 0.00075 4087 0.0169 0.0198
post_w2 18 0.0232 0.00237 4087 0.0186 0.0279
control 19 0.0175 0.00151 4087 0.0145 0.0204
post_w1 19 0.0156 0.00143 4087 0.0129 0.0184
post_w2 19 0.0289 0.00498 4087 0.0192 0.0387
control 20 0.0190 0.00179 4087 0.0155 0.0225
post_w1 20 0.0119 0.00152 4087 0.0089 0.0149
post_w2 20 0.0263 0.00466 4087 0.0172 0.0354
control 21 0.0122 0.00194 4087 0.0084 0.0160
post_w1 21 0.0154 0.00226 4087 0.0110 0.0198
post_w2 21 0.0190 0.00465 4087 0.0099 0.0281
control 22 0.0121 0.00112 4087 0.0099 0.0143
post_w1 22 0.0197 0.00167 4087 0.0164 0.0230
post_w2 22 0.0137 0.00234 4087 0.0091 0.0183
control 23 0.0166 0.00218 4087 0.0124 0.0209
post_w1 23 0.0112 0.00130 4087 0.0087 0.0138
post_w2 23 0.0187 0.00232 4087 0.0142 0.0233
control 24 0.0147 0.00202 4087 0.0107 0.0186
post_w1 24 0.0160 0.00111 4087 0.0138 0.0182
post_w2 24 0.0147 0.00207 4087 0.0106 0.0187
control 25 0.0225 0.00240 4087 0.0178 0.0273
post_w1 25 0.0122 0.00146 4087 0.0093 0.0151
post_w2 25 0.0103 0.00222 4087 0.0059 0.0146
control 26 0.0199 0.00345 4087 0.0131 0.0267
post_w1 26 0.0127 0.00209 4087 0.0086 0.0168
post_w2 26 0.0183 0.00366 4087 0.0111 0.0255
control 27 0.0114 0.00149 4087 0.0085 0.0143
post_w1 27 0.0172 0.00158 4087 0.0141 0.0203
post_w2 27 0.0130 0.00199 4087 0.0091 0.0169
control 28 0.0143 0.00129 4087 0.0118 0.0169
post_w1 28 0.0095 0.00073 4087 0.0081 0.0109
post_w2 28 0.0141 0.00329 4087 0.0077 0.0206
control 29 0.0111 0.00145 4087 0.0083 0.0140
post_w1 29 0.0165 0.00172 4087 0.0132 0.0199
post_w2 29 0.0157 0.00383 4087 0.0082 0.0232
control 30 0.0107 0.00145 4087 0.0079 0.0136
post_w1 30 0.0108 0.00098 4087 0.0089 0.0127
post_w2 30 0.0158 0.00237 4087 0.0111 0.0204
control 31 0.0107 0.00073 4087 0.0093 0.0122
post_w1 31 0.0130 0.00097 4087 0.0111 0.0149
post_w2 31 0.0116 0.00194 4087 0.0078 0.0154
control 32 0.0110 0.00087 4087 0.0093 0.0127
post_w1 32 0.0106 0.00101 4087 0.0087 0.0126
post_w2 32 0.0116 0.00139 4087 0.0088 0.0143
control 33 0.0118 0.00094 4087 0.0099 0.0136
post_w1 33 0.0088 0.00087 4087 0.0071 0.0105
post_w2 33 0.0117 0.00201 4087 0.0078 0.0156
control 34 0.0075 0.00089 4087 0.0058 0.0093
post_w1 34 0.0101 0.00119 4087 0.0078 0.0125
post_w2 34 0.0081 0.00235 4087 0.0035 0.0127
control 35 0.0081 0.00091 4087 0.0063 0.0098
post_w1 35 0.0125 0.00105 4087 0.0104 0.0146
post_w2 35 0.0038 0.00265 4087 -0.0014 0.0090
control 36 0.0075 0.00087 4087 0.0058 0.0092
post_w1 36 0.0085 0.00149 4087 0.0056 0.0114
post_w2 36 0.0080 0.00325 4087 0.0017 0.0144
control 37 0.0062 0.00088 4087 0.0045 0.0079
post_w1 37 0.0063 0.00069 4087 0.0049 0.0076
post_w2 37 0.0079 0.00160 4087 0.0048 0.0111
control 38 0.0116 0.00164 4087 0.0084 0.0148
post_w1 38 0.0069 0.00097 4087 0.0050 0.0089
post_w2 38 0.0049 0.01210 4087 -0.0188 0.0286
control 39 0.0066 0.00161 4087 0.0034 0.0097
post_w1 39 0.0056 0.00067 4087 0.0043 0.0069
post_w2 39 0.0077 0.00110 4087 0.0056 0.0099
control 40 0.0059 0.00103 4087 0.0038 0.0079
post_w1 40 0.0087 0.00179 4087 0.0052 0.0122
post_w2 40 0.0070 0.00189 4087 0.0033 0.0107
control 41 0.0084 0.00174 4087 0.0050 0.0118
post_w1 41 0.0074 0.00097 4087 0.0055 0.0093
post_w2 41 0.0114 0.00622 4087 -0.0008 0.0236
control 42 0.0061 0.00243 4087 0.0014 0.0109
post_w1 42 0.0083 0.00129 4087 0.0057 0.0108
post_w2 42 0.0071 0.00199 4087 0.0032 0.0110
control 43 0.0064 0.00180 4087 0.0029 0.0099
post_w1 43 0.0066 0.00069 4087 0.0052 0.0080
post_w2 43 0.0045 0.00116 4087 0.0022 0.0068
Covariance estimate used: vbeta
Confidence level used: 0.95
gee_contrast_3ct <- contrast(gee_emm_3ct, method = "pairwise", by = "syllable", adjust = "tukey")
summary(gee_contrast_3ct)
syllable = 0:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0199 0.00829 4087 2.400 0.0430
control - post_w2 0.0040 0.01140 4087 0.350 0.9360
post_w1 - post_w2 -0.0160 0.01040 4087 -1.530 0.2770
syllable = 1:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0222 0.01050 4087 2.120 0.0870
control - post_w2 0.0376 0.01260 4087 3.000 0.0080
post_w1 - post_w2 0.0154 0.01060 4087 1.460 0.3100
syllable = 2:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0071 0.00282 4087 -2.510 0.0320
control - post_w2 -0.0098 0.00469 4087 -2.090 0.0920
post_w1 - post_w2 -0.0027 0.00478 4087 -0.570 0.8350
syllable = 3:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0118 0.00453 4087 2.600 0.0250
control - post_w2 -0.0107 0.00781 4087 -1.370 0.3560
post_w1 - post_w2 -0.0225 0.00780 4087 -2.890 0.0110
syllable = 4:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0113 0.00376 4087 3.010 0.0070
control - post_w2 0.0112 0.00403 4087 2.770 0.0160
post_w1 - post_w2 -0.0001 0.00329 4087 -0.050 0.9990
syllable = 5:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0000 0.00394 4087 0.010 1.0000
control - post_w2 -0.0047 0.00385 4087 -1.210 0.4440
post_w1 - post_w2 -0.0047 0.00372 4087 -1.270 0.4140
syllable = 6:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0206 0.00662 4087 -3.110 0.0050
control - post_w2 -0.0069 0.00869 4087 -0.790 0.7080
post_w1 - post_w2 0.0137 0.00952 4087 1.440 0.3210
syllable = 7:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0029 0.00431 4087 -0.670 0.7790
control - post_w2 -0.0066 0.00503 4087 -1.300 0.3940
post_w1 - post_w2 -0.0037 0.00483 4087 -0.760 0.7300
syllable = 8:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0126 0.00369 4087 -3.410 0.0020
control - post_w2 0.0064 0.00491 4087 1.310 0.3900
post_w1 - post_w2 0.0190 0.00481 4087 3.950 <.0001
syllable = 9:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0021 0.00474 4087 -0.430 0.9010
control - post_w2 -0.0039 0.00365 4087 -1.070 0.5350
post_w1 - post_w2 -0.0018 0.00485 4087 -0.380 0.9250
syllable = 10:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0062 0.00389 4087 1.590 0.2520
control - post_w2 -0.0080 0.00698 4087 -1.140 0.4880
post_w1 - post_w2 -0.0141 0.00678 4087 -2.090 0.0930
syllable = 11:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0064 0.00263 4087 -2.430 0.0400
control - post_w2 -0.0137 0.00370 4087 -3.710 0.0010
post_w1 - post_w2 -0.0073 0.00405 4087 -1.810 0.1660
syllable = 12:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0014 0.00225 4087 -0.610 0.8160
control - post_w2 -0.0135 0.00408 4087 -3.310 0.0030
post_w1 - post_w2 -0.0121 0.00387 4087 -3.130 0.0050
syllable = 13:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0025 0.00288 4087 -0.870 0.6570
control - post_w2 0.0153 0.00414 4087 3.690 0.0010
post_w1 - post_w2 0.0178 0.00397 4087 4.480 <.0001
syllable = 14:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0056 0.00364 4087 -1.550 0.2670
control - post_w2 0.0035 0.00375 4087 0.920 0.6270
post_w1 - post_w2 0.0091 0.00438 4087 2.080 0.0950
syllable = 15:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0001 0.00203 4087 0.060 0.9980
control - post_w2 -0.0056 0.00377 4087 -1.480 0.3020
post_w1 - post_w2 -0.0057 0.00364 4087 -1.570 0.2610
syllable = 16:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0117 0.00333 4087 -3.500 0.0010
control - post_w2 0.0040 0.00272 4087 1.480 0.3010
post_w1 - post_w2 0.0157 0.00362 4087 4.340 <.0001
syllable = 17:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0021 0.00244 4087 0.870 0.6610
control - post_w2 0.0117 0.00240 4087 4.870 <.0001
post_w1 - post_w2 0.0096 0.00253 4087 3.780 <.0001
syllable = 18:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0036 0.00147 4087 2.470 0.0360
control - post_w2 -0.0012 0.00268 4087 -0.460 0.8910
post_w1 - post_w2 -0.0048 0.00248 4087 -1.950 0.1240
syllable = 19:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0018 0.00208 4087 0.870 0.6590
control - post_w2 -0.0115 0.00520 4087 -2.210 0.0700
post_w1 - post_w2 -0.0133 0.00518 4087 -2.570 0.0280
syllable = 20:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0071 0.00235 4087 3.030 0.0070
control - post_w2 -0.0073 0.00499 4087 -1.460 0.3110
post_w1 - post_w2 -0.0144 0.00490 4087 -2.940 0.0090
syllable = 21:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0032 0.00298 4087 -1.070 0.5300
control - post_w2 -0.0068 0.00504 4087 -1.360 0.3630
post_w1 - post_w2 -0.0036 0.00517 4087 -0.700 0.7610
syllable = 22:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0076 0.00201 4087 -3.780 <.0001
control - post_w2 -0.0017 0.00260 4087 -0.640 0.7990
post_w1 - post_w2 0.0060 0.00288 4087 2.070 0.0960
syllable = 23:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0054 0.00254 4087 2.130 0.0840
control - post_w2 -0.0021 0.00318 4087 -0.660 0.7850
post_w1 - post_w2 -0.0075 0.00267 4087 -2.820 0.0130
syllable = 24:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0013 0.00231 4087 -0.570 0.8340
control - post_w2 0.0000 0.00289 4087 -0.010 1.0000
post_w1 - post_w2 0.0013 0.00235 4087 0.550 0.8470
syllable = 25:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0104 0.00281 4087 3.680 0.0010
control - post_w2 0.0123 0.00327 4087 3.750 0.0010
post_w1 - post_w2 0.0019 0.00266 4087 0.720 0.7510
syllable = 26:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0072 0.00403 4087 1.800 0.1710
control - post_w2 0.0016 0.00503 4087 0.320 0.9450
post_w1 - post_w2 -0.0056 0.00422 4087 -1.330 0.3760
syllable = 27:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0058 0.00217 4087 -2.660 0.0210
control - post_w2 -0.0016 0.00248 4087 -0.640 0.8000
post_w1 - post_w2 0.0042 0.00254 4087 1.650 0.2240
syllable = 28:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0049 0.00148 4087 3.280 0.0030
control - post_w2 0.0002 0.00354 4087 0.070 0.9970
post_w1 - post_w2 -0.0046 0.00337 4087 -1.370 0.3570
syllable = 29:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0054 0.00225 4087 -2.410 0.0430
control - post_w2 -0.0046 0.00409 4087 -1.130 0.4960
post_w1 - post_w2 0.0008 0.00420 4087 0.190 0.9810
syllable = 30:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0000 0.00175 4087 -0.020 1.0000
control - post_w2 -0.0050 0.00278 4087 -1.810 0.1670
post_w1 - post_w2 -0.0050 0.00256 4087 -1.950 0.1260
syllable = 31:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0023 0.00122 4087 -1.870 0.1490
control - post_w2 -0.0008 0.00207 4087 -0.400 0.9160
post_w1 - post_w2 0.0014 0.00217 4087 0.670 0.7840
syllable = 32:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0004 0.00133 4087 0.280 0.9590
control - post_w2 -0.0006 0.00164 4087 -0.340 0.9380
post_w1 - post_w2 -0.0009 0.00171 4087 -0.540 0.8520
syllable = 33:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0029 0.00128 4087 2.280 0.0580
control - post_w2 0.0001 0.00222 4087 0.030 1.0000
post_w1 - post_w2 -0.0029 0.00219 4087 -1.310 0.3890
syllable = 34:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0026 0.00149 4087 -1.750 0.1870
control - post_w2 -0.0005 0.00251 4087 -0.210 0.9770
post_w1 - post_w2 0.0021 0.00264 4087 0.790 0.7100
syllable = 35:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0044 0.00139 4087 -3.170 0.0040
control - post_w2 0.0043 0.00280 4087 1.520 0.2810
post_w1 - post_w2 0.0087 0.00285 4087 3.050 0.0070
syllable = 36:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0010 0.00172 4087 -0.580 0.8320
control - post_w2 -0.0005 0.00336 4087 -0.150 0.9870
post_w1 - post_w2 0.0005 0.00357 4087 0.140 0.9900
syllable = 37:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0001 0.00112 4087 -0.080 0.9970
control - post_w2 -0.0017 0.00183 4087 -0.960 0.6040
post_w1 - post_w2 -0.0017 0.00174 4087 -0.950 0.6080
syllable = 38:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0047 0.00190 4087 2.460 0.0370
control - post_w2 0.0067 0.01220 4087 0.550 0.8470
post_w1 - post_w2 0.0020 0.01210 4087 0.170 0.9850
syllable = 39:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0010 0.00175 4087 0.560 0.8430
control - post_w2 -0.0012 0.00196 4087 -0.610 0.8150
post_w1 - post_w2 -0.0022 0.00129 4087 -1.680 0.2140
syllable = 40:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0028 0.00206 4087 -1.370 0.3590
control - post_w2 -0.0011 0.00215 4087 -0.510 0.8650
post_w1 - post_w2 0.0017 0.00260 4087 0.660 0.7880
syllable = 41:
contrast estimate SE df t.ratio p.value
control - post_w1 0.0010 0.00199 4087 0.490 0.8740
control - post_w2 -0.0030 0.00646 4087 -0.470 0.8850
post_w1 - post_w2 -0.0040 0.00629 4087 -0.640 0.7980
syllable = 42:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0021 0.00275 4087 -0.770 0.7210
control - post_w2 -0.0009 0.00314 4087 -0.290 0.9530
post_w1 - post_w2 0.0012 0.00237 4087 0.500 0.8700
syllable = 43:
contrast estimate SE df t.ratio p.value
control - post_w1 -0.0002 0.00192 4087 -0.110 0.9940
control - post_w2 0.0019 0.00214 4087 0.890 0.6480
post_w1 - post_w2 0.0021 0.00135 4087 1.560 0.2640
P value adjustment: tukey method for comparing a family of 3 estimates
#this data will be used for plotting
# Convert the pairwise results into a data frame using summary
pairwise_results_3ct_gee <- summary(gee_contrast_3ct)
# Filter significant results (p-value < 0.05)
sig_results_3ct_gee <- pairwise_results_3ct_gee[pairwise_results_3ct_gee$p.value < 0.05, ]
# Create a data frame for significant syllables, labels, and contrast groups
sig_syllables_3ct_gee <- sig_results_3ct_gee %>%
mutate(label = ifelse(p.value < 0.001, "***",
ifelse(p.value < 0.01, "**",
ifelse(p.value < 0.05, "*", "ns")))) %>%
select(contrast, syllable, label) # Add 'contrast' column for group comparisons
#make factor levels the same for sig syllables and x-axis
sig_syllables_3ct_gee <- sig_syllables_3ct_gee %>%
mutate(syllable = factor(syllable, levels = syllable_order_3ct_gee))
# Print sig_syllables to check
print(sig_syllables_3ct_gee)
# Get syllables in descending order of emmean from the control group
syllable_order_3ct_gee <- emm_df_3ct_gee %>%
filter(group == "control") %>%
arrange(desc(emmean)) %>% #computed mean frequency sorted from most to least
pull(syllable) %>% # Extract just the ordered syllable names, this controls x-axis of plot
as.character()
# Reapply the factor with new levels
emm_df_3ct_gee <- emm_df_3ct_gee %>%
mutate(syllable = factor(syllable, levels = syllable_order_3ct_gee))
emm_df_3ct_gee
NA
#check if factor ordering is same
levels(emm_df_3ct_gee$syllable)
[1] "1" "0" "4" "3" "5" "2" "7" "9" "8" "13" "6" "10" "17" "14" "12" "15" "11" "25" "18" "16" "26"
[22] "20" "19" "23" "24" "28" "21" "22" "33" "38" "27" "29" "32" "31" "30" "41" "35" "34" "36" "39" "43" "37"
[43] "42" "40"
levels(sig_syllables_3ct_gee$syllable)
[1] "1" "0" "4" "3" "5" "2" "7" "9" "8" "13" "6" "10" "17" "14" "12" "15" "11" "25" "18" "16" "26"
[22] "20" "19" "23" "24" "28" "21" "22" "33" "38" "27" "29" "32" "31" "30" "41" "35" "34" "36" "39" "43" "37"
[43] "42" "40"
# Create the plot
plot_3ct_gee <- ggplot(emm_df_3ct_gee, aes(x = syllable, y = emmean, color = group, group = group)) +
# Add lines connecting the means for each group
# geom_line(size = 1) +
# Add points at the means for each group
geom_point(size = 3) +
# Add error bars for standard error
geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE), width = 0.2) +
# Custom colors for different groups
scale_color_manual(values = c("control" = "#feca8d", "post_w1" = "#f1605d", "post_w2" = "#440f76")) +
scale_x_discrete(labels = syllable_labels_3ct) +
# Labels for axes and legend
labs(
x = "Syllable Order by Frequency",
y = "Frequency",
color = NULL
) +
ylim(0, 0.3) +
# Apply clean theme
theme_bw() +
theme(
text = element_text(size = 13),
panel.grid.minor = element_blank(),
legend.position = "right",
legend.box.margin = margin(0, 50, 0, 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1, margin = margin(b = 0)) #angle of x-axis text below and spacing
)
# Add significance asterisks
plot_3ct_gee <- plot_3ct_gee + geom_text(
data = sig_syllables_3ct_gee,
aes(x = as.numeric(as.factor(syllable)), #(factor makes sure lines up with x-axis syllables)
# Determine y position based on contrast type
y = case_when(
contrast == "control - post_w1" ~ 0.28,
contrast == "post_w1 - post_w2" ~ 0.24,
contrast == "control - post_w2" ~ 0.20,
TRUE ~ 0.20 # Default position for any other contrast
),
label = label),
color = "black",
size = 5,
inherit.aes = FALSE
)
plot_3ct_gee
#ggsave("3ct_graph(SE)_gee.png", plot = plot_3ct_gee, width = 15, height = 6) #makes spaces visible
#robust LLM OFT
model_oft_log <- lmer(log(frequency) ~ group * syllable + (1 | ID), data = df_oft)
#assumption check 1 - Normality of residuals (should be normally distributed) - violates
qqnorm(resid(model_oft_log))
qqline(resid(model_oft_log))
#Assumption 2 - Homoscedasticity (variance should be consistent) - VIOLATES
plot(fitted(model_oft_log), resid(model_oft_log))
# Obtain estimated marginal means
emm_oft_log <- emmeans(model_oft_log, ~ group | syllable) # Pairwise comparisons of syllable effects within each group
head(emm_oft_log)
group syllable emmean SE df lower.CL upper.CL
control 0 -1.90 0.194 890 -2.28 -1.52
post_w1 0 -1.77 0.194 890 -2.15 -1.39
post_w2 0 -2.01 0.212 890 -2.43 -1.60
control 1 -2.02 0.194 890 -2.40 -1.64
post_w1 1 -1.98 0.194 890 -2.37 -1.60
post_w2 1 -1.97 0.212 890 -2.38 -1.55
Degrees-of-freedom method: kenward-roger
Results are given on the log (not the response) scale.
Confidence level used: 0.95
#for hetereodtasicity
coef_test(model_oft, vcov = "CR2", cluster = df_oft$ID)
Alternative hypothesis: two-sided